Skip to content

Commit

Permalink
Mask: Tweaks to optional position handling - should now hide optional…
Browse files Browse the repository at this point in the history
… section after focus leaves as well
  • Loading branch information
gnarf committed Oct 12, 2011
1 parent 23fb658 commit 9a1483a
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions ui/jquery.ui.mask.js
Expand Up @@ -115,7 +115,7 @@ $.widget( "ui.mask", {
this._caret( bufferPosition ); this._caret( bufferPosition );
} }
}, },
_getValue: function( raw ) { _getValue: function( raw, focused ) {
var bufferPosition, bufferObject, counter, var bufferPosition, bufferObject, counter,
bufferLength = this.buffer.length, bufferLength = this.buffer.length,
value = "", value = "",
Expand Down Expand Up @@ -147,7 +147,13 @@ $.widget( "ui.mask", {


// don't display the "optional" portion until the input is "valid" or there are // don't display the "optional" portion until the input is "valid" or there are
// values past the optional position // values past the optional position
if ( lastValue < this.optionalPosition && !this.isValid ) { if ( this.options.clearEmpty && this.isEmpty && focused === false ) {
return "";
}

// strip the optional parts off if we haven't gotten there yet, or there are no values past it
// and we aren't focused
if ( lastValue <= this.optionalPosition && !( this.isValid && focused ) ) {
value = value.substr( 0, this.optionalPosition ); value = value.substr( 0, this.optionalPosition );
} }
return value; return value;
Expand Down Expand Up @@ -277,14 +283,7 @@ $.widget( "ui.mask", {
if ( focused === undefined ) { if ( focused === undefined ) {
focused = this.element[ 0 ] === document.activeElement; focused = this.element[ 0 ] === document.activeElement;
} }
// calling _getValue updates isEmpty this.element.val( this._getValue( false, focused ) );
var value = this._getValue();

if ( this.options.clearEmpty && this.isEmpty && !focused ) {
this.element.val( "" );
} else {
this.element.val( value );
}
}, },
_parseMask: function() { _parseMask: function() {
var key, x, bufferObject, optionalPosition, var key, x, bufferObject, optionalPosition,
Expand Down

0 comments on commit 9a1483a

Please sign in to comment.