Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Mask: Optional fields not displayed until the value is 'valid', or th…

…ere are characters in the 'optional' area
  • Loading branch information...
commit 23fb65809714b8411b2298fff4a17017d4a9372a 1 parent 27e229a
@gnarf gnarf authored
Showing with 12 additions and 2 deletions.
  1. +12 −2 ui/jquery.ui.mask.js
View
14 ui/jquery.ui.mask.js
@@ -118,14 +118,18 @@ $.widget( "ui.mask", {
_getValue: function( raw ) {
var bufferPosition, bufferObject, counter,
bufferLength = this.buffer.length,
- value = "";
+ value = "",
+ lastValue = 0;
this.isEmpty = this.isValid = true;
for ( bufferPosition = 0; bufferPosition < bufferLength; bufferPosition += bufferObject.length ) {
bufferObject = this.buffer[ bufferPosition ];
if ( bufferObject.literal && !raw ) {
- value += bufferObject.literal;
+ if ( bufferPosition < this.optionalPosition || this.isValid ) {
+ value += bufferObject.literal;
+ }
} else if ( bufferObject.value ) {
+ lastValue = bufferObject.start + bufferObject.length;
this.isEmpty = false;
value += bufferObject.value;
for ( counter = bufferObject.value.length; counter < bufferObject.length; counter++ ) {
@@ -140,6 +144,12 @@ $.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 ) {
+ value = value.substr( 0, this.optionalPosition );
+ }
return value;
},
_events: {
Please sign in to comment.
Something went wrong with that request. Please try again.