File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 5353< div id ="app "> </ div >
5454< script type ="text/jsx;harmony=true "> void function ( ) { 'use strict' ;
5555
56+ var PATTERNS = [
57+ '1111 1111' ,
58+ '111 111' ,
59+ '11 11' ,
60+ '1 1'
61+ ]
62+
5663var App = React . createClass ( {
5764 getInitialState ( ) {
5865 return {
6168 ccv : '' ,
6269 plate : '' ,
6370 escaped : '' ,
64- custom : ''
71+ custom : '' ,
72+ changing : '' ,
73+ pattern : '1111 1111'
6574 }
6675 } ,
6776
7180 this . setState ( stateChange )
7281 } ,
7382
83+ _changePattern ( e ) {
84+ this . setState ( { pattern : e . target . value } )
85+ } ,
86+
7487 render ( ) {
7588 return < div className = "App" >
7689 < h1 > < code > << a href = "https://github.com/insin/react-maskedinput" > MaskedInput</ a > /></ code > </ h1 >
@@ -97,6 +110,17 @@ <h1><code><<a href="https://github.com/insin/react-maskedinput">MaskedInput</
97110 < label htmlFor = "escaped" > Escaped:</ label >
98111 < MaskedInput pattern = "11 \* 11" name = "escaped" id = "escaped" onChange = { this . _onChange } />
99112 </ div >
113+ < p > Changing patterns:</ p >
114+ < div className = "form-field" >
115+ < label htmlFor = "changing" > Input:</ label >
116+ < MaskedInput pattern = { this . state . pattern } name = "changing" id = "changing" onChange = { this . _onChange } />
117+ </ div >
118+ < div className = "form-field" >
119+ < label htmlFor = "pattern" > Pattern:</ label >
120+ < select onChange = { this . _changePattern } >
121+ { PATTERNS . map ( pattern => < option value = { pattern } > { pattern } </ option > ) }
122+ </ select >
123+ </ div >
100124 < p > Custom format character (W=[a-zA-Z0-9_], transformed to uppercase) and placeholder character (en space):</ p >
101125 < div className = "form-field" >
102126 < label htmlFor = "custom" > Custom:</ label >
Original file line number Diff line number Diff line change @@ -42,6 +42,12 @@ var MaskedInput = React.createClass({
4242 this . mask = new InputMask ( options )
4343 } ,
4444
45+ componentWillReceiveProps ( nextProps ) {
46+ if ( this . props . pattern !== nextProps . pattern ) {
47+ this . mask . setPattern ( nextProps . pattern , { value : this . mask . getRawValue ( ) } )
48+ }
49+ } ,
50+
4551 _updateMaskSelection ( ) {
4652 this . mask . selection = getSelection ( this . getDOMNode ( ) )
4753 } ,
You can’t perform that action at this time.
0 commit comments