@@ -68,7 +68,7 @@ var DEFAULT_FORMAT_CHARACTERS = {
6868 * @param {string } source
6969 * @patam {?Object} formatCharacters
7070 */
71- function Pattern ( source , formatCharacters , placeholderChar ) {
71+ function Pattern ( source , formatCharacters , placeholderChar , isRevealingMask ) {
7272 if ( ! ( this instanceof Pattern ) ) {
7373 return new Pattern ( source , formatCharacters , placeholderChar )
7474 }
@@ -87,9 +87,10 @@ function Pattern(source, formatCharacters, placeholderChar) {
8787 this . firstEditableIndex = null
8888 /** Index of the last editable character. */
8989 this . lastEditableIndex = null
90-
9190 /** Lookup for indices of editable characters in the pattern. */
9291 this . _editableIndices = { }
92+ /** If true, only the pattern before the last valid value character shows. */
93+ this . isRevealingMask = isRevealingMask || false
9394
9495 this . _parse ( )
9596}
@@ -139,6 +140,11 @@ Pattern.prototype.formatValue = function format(value) {
139140
140141 for ( var i = 0 , l = this . length ; i < l ; i ++ ) {
141142 if ( this . isEditableIndex ( i ) ) {
143+ if ( this . isRevealingMask &&
144+ value . length <= valueIndex &&
145+ ! this . isValidAtIndex ( value [ valueIndex ] , i ) ) {
146+ break
147+ }
142148 valueBuffer [ i ] = ( value . length > valueIndex && this . isValidAtIndex ( value [ valueIndex ] , i )
143149 ? this . transform ( value [ valueIndex ] , i )
144150 : this . placeholderChar )
@@ -181,10 +187,10 @@ Pattern.prototype.transform = function transform(char, index) {
181187
182188function InputMask ( options ) {
183189 if ( ! ( this instanceof InputMask ) ) { return new InputMask ( options ) }
184-
185190 options = extend ( {
186191 formatCharacters : null ,
187192 pattern : null ,
193+ isRevealingMask : false ,
188194 placeholderChar : DEFAULT_PLACEHOLDER_CHAR ,
189195 selection : { start : 0 , end : 0 } ,
190196 value : ''
@@ -202,7 +208,8 @@ function InputMask(options) {
202208 this . formatCharacters = mergeFormatCharacters ( options . formatCharacters )
203209 this . setPattern ( options . pattern , {
204210 value : options . value ,
205- selection : options . selection
211+ selection : options . selection ,
212+ isRevealingMask : options . isRevealingMask
206213 } )
207214}
208215
@@ -446,7 +453,7 @@ InputMask.prototype.setPattern = function setPattern(pattern, options) {
446453 selection : { start : 0 , end : 0 } ,
447454 value : ''
448455 } , options )
449- this . pattern = new Pattern ( pattern , this . formatCharacters , this . placeholderChar )
456+ this . pattern = new Pattern ( pattern , this . formatCharacters , this . placeholderChar , options . isRevealingMask )
450457 this . setValue ( options . value )
451458 this . emptyValue = this . pattern . formatValue ( [ ] ) . join ( '' )
452459 this . selection = options . selection
0 commit comments