Skip to content

Commit c093bf1

Browse files
Matt Wanneraxelson
authored andcommitted
fixed so masked input works with chrome auto-fill and on paste
Edit: Rebased onto latest master Only kept relevant change. Change to dist was dropped to help avoid merge conflicts Add phone number example to demo page
1 parent 53b566c commit c093bf1

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

demo/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
leading: '',
7373
custom: '',
7474
changing: '',
75+
phone: '',
7576
pattern: '1111 1111'
7677
}
7778
},
@@ -112,6 +113,10 @@ <h1><code>&lt;<a href="https://github.com/insin/react-maskedinput">MaskedInput</
112113
<label htmlFor="plate">License Plate:</label>
113114
<MaskedInput mask="AAA 1111" name="plate" id="plate" onChange={this._onChange} placeholder="ABC 1234"/>
114115
</div>
116+
<div className="form-field">
117+
<label htmlFor="phone">Phone Number:</label>
118+
<MaskedInput mask="(111) 111-1111" name="phone" id="phone" onChange={this._onChange} placeholder="(999) 999-9999"/>
119+
</div>
115120
<p>Mask placeholder characters can be escaped with a leading <code>\</code> to use them as static contents:</p>
116121
<div className="form-field">
117122
<label htmlFor="escaped">Escaped:</label>

src/index.jsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ var MaskedInput = React.createClass({
7171
this.mask.selection.end = this.mask.selection.start + sizeDiff
7272
this.mask.backspace()
7373
}
74+
this.mask.setValue(e.target.value);
7475
var value = this._getDisplayValue()
7576
e.target.value = value
7677
if (value) {
@@ -146,6 +147,14 @@ var MaskedInput = React.createClass({
146147
setTimeout(this._updateInputSelection, 0)
147148
this.props.onChange(e)
148149
}
150+
else {
151+
this.mask.setValue(e.clipboardData.getData('Text'));
152+
var value = this._getDisplayValue()
153+
e.target.value = value
154+
if (value) {
155+
this._updateInputSelection()
156+
}
157+
}
149158
},
150159

151160
_getDisplayValue() {

0 commit comments

Comments
 (0)