Skip to content

Commit

Permalink
Fixed #413
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed May 29, 2018
1 parent e644799 commit e044b98
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions src/components/inputmask/InputMask.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ export class InputMask extends Component {
}

checkVal(allow) {
this.isValueChecked = true;
//try to place characters where they belong
let test = this.input.value,
lastMatch = -1,
Expand Down Expand Up @@ -434,6 +435,31 @@ export class InputMask extends Component {
this.filled = this.input && this.input.value !== '';
}

updateValue() {
this.value = this.props.value;

if (this.input) {
if (this.value === undefined || this.value === null) {
this.input.value = '';
}
else {
this.input.value = this.value;
this.checkVal();
}

setTimeout(() => {
if(this.input) {
this.writeBuffer();
this.checkVal();
}
}, 10);

this.focusText = this.input.value;
}

this.updateFilledState();
}

init() {
this.tests = [];
this.partialPosition = this.props.mask.length;
Expand Down Expand Up @@ -484,32 +510,14 @@ export class InputMask extends Component {

componentDidMount() {
this.init();

this.value = this.props.value;

if (this.input) {
if (this.value === undefined || this.value === null) {
this.input.value = '';
}
else {
this.input.value = this.value;
this.checkVal();
}

setTimeout(() => {
if(this.input) {
this.writeBuffer();
this.checkVal();
}
}, 10);

this.focusText = this.input.value;
}

this.updateFilledState();
this.updateValue();
}

render() {
if(this.input && this.input.value !== this.props.value) {
this.updateValue();
}

return (
<InputText id={this.props.id} ref={(el) => this.input = ReactDOM.findDOMNode(el)} type={this.props.type} name={this.props.name} style={this.props.style} className={this.props.className} placeholder={this.props.placeholder}
size={this.props.size} maxLength={this.props.maxlength} tabIndex={this.props.tabindex} disabled={this.props.disabled} readOnly={this.props.readonly}
Expand Down

0 comments on commit e044b98

Please sign in to comment.