Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Mask: Tweaks to optional position handling - should now hide optional…

… section after focus leaves as well
  • Loading branch information...
commit 9a1483a3d6cbab3472ceb52a4b19d3d8eb6bcb71 1 parent 23fb658
@gnarf gnarf authored
Showing with 9 additions and 10 deletions.
  1. +9 −10 ui/jquery.ui.mask.js
View
19 ui/jquery.ui.mask.js
@@ -115,7 +115,7 @@ $.widget( "ui.mask", {
this._caret( bufferPosition );
}
},
- _getValue: function( raw ) {
+ _getValue: function( raw, focused ) {
var bufferPosition, bufferObject, counter,
bufferLength = this.buffer.length,
value = "",
@@ -147,7 +147,13 @@ $.widget( "ui.mask", {
// don't display the "optional" portion until the input is "valid" or there are
// 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 );
}
return value;
@@ -277,14 +283,7 @@ $.widget( "ui.mask", {
if ( focused === undefined ) {
focused = this.element[ 0 ] === document.activeElement;
}
- // calling _getValue updates isEmpty
- var value = this._getValue();
-
- if ( this.options.clearEmpty && this.isEmpty && !focused ) {
- this.element.val( "" );
- } else {
- this.element.val( value );
- }
+ this.element.val( this._getValue( false, focused ) );
},
_parseMask: function() {
var key, x, bufferObject, optionalPosition,
Please sign in to comment.
Something went wrong with that request. Please try again.