Skip to content
Browse files

Mask: Adding a short delay to setting the caret position on focus

  • Loading branch information...
1 parent a84baa5 commit 548ccaed10c9def7f86124c068d810435a2a9d8c @gnarf gnarf committed Aug 2, 2011
Showing with 17 additions and 8 deletions.
  1. +14 −7 tests/unit/mask/mask_events.js
  2. +3 −1 ui/jquery.ui.mask.js
View
21 tests/unit/mask/mask_events.js
@@ -4,18 +4,25 @@ module( "mask: events" );
/* TODO: Descide behavior of bluring non-valid inputs */
-test( "focus: Initial Caret Positioning", function() {
+asyncTest( "focus: Initial Caret Positioning", function() {
var input = $( "#mask1" ).val("").mask({ mask: "9" }),
mask = input.data( "mask" );
equal( input.val(), "_", "Initial Value Expected" );
input.focus();
- deepEqual( mask._caret(), { begin: 0, end: 0 }, "Caret position correct");
+ setTimeout( function() {
+ deepEqual( mask._caret(), { begin: 0, end: 0 }, "Caret position correct");
- input.mask( "option", "mask", "(9)" );
- equal( input.val(), "(_)", "Initial Value Expected" );
- input.focus();
- deepEqual( mask._caret(), { begin: 1, end: 1 }, "Caret position correct");
+ input.mask( "option", "mask", "(9)" );
+ equal( input.val(), "(_)", "Initial Value Expected" );
+ input.focus();
+
+ setTimeout( function() {
+ deepEqual( mask._caret(), { begin: 1, end: 1 }, "Caret position correct");
+ start();
+ }, 0);
+
+ }, 0);
});
@@ -169,7 +176,7 @@ test( "keypress: typing behaviors", function() {
input.simulate( "keypress", { keyCode: "2".charCodeAt( 0 ) });
equal( input.val(), "2-1", "Typed a 2 before the 1" );
deepEqual( mask._caret(), { begin: 2, end: 2 }, "Caret position correct");
-
+
input.val("").mask( "option", "mask", "9-a" );
equal( input.val(), "_-_", "Initial value expected" );
View
4 ui/jquery.ui.mask.js
@@ -161,7 +161,9 @@ $.widget( "ui.mask", {
this._bind({
focus: function( event ) {
lastUnsavedValue = elem.val();
- that._caret( that._seekRight( that._parseValue() - 1 ) );
+ setTimeout( function() {
+ that._caret( that._seekRight( that._parseValue() - 1 ) );
+ }, 0);
},
blur: function( event ) {

0 comments on commit 548ccae

Please sign in to comment.
Something went wrong with that request. Please try again.