Skip to content

Commit

Permalink
Fixed #391
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Apr 24, 2018
1 parent 6c9129a commit f832b8f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/components/inputtext/InputText.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ export class InputText extends Component {
static defaultProps = {
onInput: null,
onKeyPress: null,
keyfilter: null
keyfilter: null,
validateOnly: false,
};

static propTypes = {
onInput: PropTypes.func,
onKeyPress: PropTypes.func,
keyfilter: PropTypes.any
keyfilter: PropTypes.any,
validateOnly: PropTypes.bool
};

constructor(props) {
Expand All @@ -29,13 +31,18 @@ export class InputText extends Component {
}

if (this.props.keyfilter) {
KeyFilter.onKeyPress(event, this.props.keyfilter)
KeyFilter.onKeyPress(event, this.props.keyfilter, this.props.validateOnly)
}
}

onInput(e) {
let validatePattern = true;
if (this.props.keyfilter && this.props.validateOnly) {
validatePattern = KeyFilter.validate(e, this.props.keyfilter);
}

if(this.props.onInput) {
this.props.onInput(e);
this.props.onInput(e, validatePattern);
}

this.updateFilledState(e.target.value);
Expand Down Expand Up @@ -69,6 +76,7 @@ export class InputText extends Component {
delete inputProps.onInput;
delete inputProps.onKeyPress;
delete inputProps.keyfilter;
delete inputProps.validateOnly;

return <input ref={(el) => this.inputEl = el} {...inputProps} className={className} onInput={this.onInput} onKeyPress={this.onKeyPress}/>;
}
Expand Down
17 changes: 16 additions & 1 deletion src/components/keyfilter/KeyFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ export default class KeyFilter {
return e.charCode || e.keyCode || e.which;
}

static onKeyPress(e,keyfilter) {
static onKeyPress(e,keyfilter, validateOnly) {
if(validateOnly) {
return;
}

this.regex = KeyFilter.DEFAULT_MASKS[keyfilter]? KeyFilter.DEFAULT_MASKS[keyfilter] : keyfilter;
let browser = DomHandler.getBrowser();

Expand All @@ -86,4 +90,15 @@ export default class KeyFilter {
e.preventDefault();
}
}

static validate(e, keyfilter) {
let value = e.target.value,
validatePattern = true;

if (value && !keyfilter.test(value)) {
validatePattern = false;
}

return validatePattern;
}
}

0 comments on commit f832b8f

Please sign in to comment.