Permalink
Browse files

Filterable: Reset flag "preventKeyPress" at each keydown

Remove all handlers when detaching input

Fixes gh-7830
Fixes gh-7865
Closes gh-7866
  • Loading branch information...
gabrielschulhof committed Dec 3, 2014
1 parent ba30238 commit 2ef45a1dc0a79fad010d12fb7aae3dedbd47b74b
View
@@ -154,7 +154,7 @@ $.widget( "mobile.filterable", {
}
if ( search ) {
this._off( search, "keyup change input" );
this._off( search, "keyup keydown keypress change input" );
search = null;
}
@@ -177,6 +177,7 @@ $.widget( "mobile.filterable", {
// Prevent form submission
_onKeyDown: function( event ) {
this._preventKeyPress = false;
if ( event.keyCode === $.ui.keyCode.ENTER ) {
event.preventDefault();
this._preventKeyPress = true;
@@ -362,4 +362,52 @@
]);
});
test( "Default not prevented on keystroke following 'Enter'", function() {
var event,
input = $( "#test-keyboard-flag-reset-input" );
event = $.Event( "keydown" );
event.keyCode = $.ui.keyCode.ENTER;
input.trigger( event );
deepEqual( event.isDefaultPrevented(), true, "'Enter' keydown default prevented" );
event = $.Event( "keypress" );
event.keyCode = $.ui.keyCode.ENTER;
input.trigger( event );
deepEqual( event.isDefaultPrevented(), true,
"'Enter' keypress following 'Enter' keydown default prevented" );
event = $.Event( "keydown" );
event.keyCode = $.ui.keyCode.ENTER;
input.trigger( event );
deepEqual( event.isDefaultPrevented(), true, "'Enter' keydown default prevented again" );
event = $.Event( "keydown" );
event.keyCode = 85;
input.trigger( event );
deepEqual( event.isDefaultPrevented(), false, "'u' keydown default not prevented" );
event = $.Event( "keypress" );
event.keyCode = 85;
input.trigger( event );
deepEqual( event.isDefaultPrevented(), false, "'u' keypress default not prevented" );
});
test( "All event handlers are removed from input", function() {
deepEqual( $._data( $( "#test-handler-removal-input" )[ 0 ] ), {},
"Private data for input is initially empty" );
$( "#test-handler-removal-list" )
.filterable( "option", "input", "#test-handler-removal-input" );
notDeepEqual( $._data( $( "#test-handler-removal-input" )[ 0 ] ), {},
"Private data for input not empty after setting as filterable input" );
$( "#test-handler-removal-list" )
.filterable( "option", "input", false );
deepEqual( $._data( $( "#test-handler-removal-input" )[ 0 ] ), {},
"Private data for input is empty again after unsetting as filterable input" );
});
})(jQuery);
@@ -31,7 +31,6 @@
"widgets/forms/button",
"widgets/controlgroup",
"widgets/forms/select",
"widgets/forms/textinput",
"buttonMarkup",
"widgets/forms/checkboxradio"
],
@@ -326,6 +325,28 @@ <h1>Filterable</h1>
<li>New York, NY</li>
</ul>
<input id="test-keyboard-flag-reset-input">
<ul id="test-keyboard-flag-reset-list"
data-nstest-role="listview"
data-nstest-filter="true"
data-nstest-input="#test-keyboard-flag-reset-input">
<li id="acura">Acura</li>
<li id="audi">Audi</li>
<li id="bmw">BMW</li>
<li id="cadillac">Cadillac</li>
<li id="ferrari">Ferrari</li>
</ul>
<input id="test-handler-removal-input">
<ul id="test-handler-removal-list"
data-nstest-role="listview"
data-nstest-filter="true">
<li id="acura">Acura</li>
<li id="audi">Audi</li>
<li id="bmw">BMW</li>
<li id="cadillac">Cadillac</li>
<li id="ferrari">Ferrari</li>
</ul>
</div>
</div>

0 comments on commit 2ef45a1

Please sign in to comment.