Permalink
Browse files

Filterable: fix preventDefault not working

Closes gh-7154
Fixes gh-7153
  • Loading branch information...
frequent authored and gabrielschulhof committed Feb 22, 2014
1 parent 2278fc3 commit 6b464256cefe4230512dff50568ec12886ecd3eb
@@ -72,7 +72,9 @@ $.widget( "mobile.filterable", $.mobile.filterable, {
// Also trigger listviewbeforefilter if this widget is also a listview
this._widget._trigger( "beforefilter", event, data );
}
this._super( type, event, data );
// Passing back the response enables calling preventDefault()
return this._super( type, event, data );
},
_setWidget: function( widget ) {
View
@@ -62,7 +62,9 @@ $.widget( "mobile.filterable", {
}
this._timer = this._delay( function() {
this._trigger( "beforefilter", null, { input: search } );
if ( this._trigger( "beforefilter", null, { input: search } ) === false ) {
return false;
}
// Change val as lastval for next execution
search[ 0 ].setAttribute( "data-" + $.mobile.ns + "lastval", val );
@@ -67,6 +67,29 @@
], 500 );
});
asyncTest( "Filter won't run when preventing default on 'filterablebeforefilter'", function() {
expect( 1 );
var input = $( "#test-prevent-default-handler" ),
listview = $( "#test-prevent-default-signal-emission" );
listview.on( "filterablebeforefilter.theEventIsPrevented", function (e) {
e.preventDefault();
});
$.testHelper.sequence([
function() {
input.val( "a" ).trigger( "change" );
},
function() {
deepEqual( listview.children( ".ui-screen-hidden" ).length, 0,
"No children are hidden." );
listview.off( "filterablebeforefilter.theEventIsPrevented" );
},
start
], 500);
});
asyncTest( "filterCallback and filterReveal can be altered after widget creation", function(){
var filterable = $( "#custom-callback-listview" ),
input = $( "#custom-callback-listview-input" ),
@@ -93,6 +93,17 @@ <h1>Filterable</h1>
<li>d is for darkwing</li>
</ul>
<input id="test-prevent-default-handler"></input>
<ul id="test-prevent-default-signal-emission"
data-nstest-role="listview"
data-nstest-filter="true"
data-nstest-input="#test-prevent-default-handler">
<li>San Francisco, CA</li>
<li>Portland, OR</li>
<li>Washington, DC</li>
<li>New York, NY</li>
</ul>
<input id="custom-callback-listview-input"></input>
<ul id="custom-callback-listview" data-nstest-role="listview" data-nstest-filter="true" data-nstest-input="#custom-callback-listview-input">
<li>a is for aquaman</li>

0 comments on commit 6b46425

Please sign in to comment.