diff --git a/src/components/inputtext/InputText.js b/src/components/inputtext/InputText.js index c0a728c2b9..0729027926 100644 --- a/src/components/inputtext/InputText.js +++ b/src/components/inputtext/InputText.js @@ -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) { @@ -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); @@ -69,6 +76,7 @@ export class InputText extends Component { delete inputProps.onInput; delete inputProps.onKeyPress; delete inputProps.keyfilter; + delete inputProps.validateOnly; return this.inputEl = el} {...inputProps} className={className} onInput={this.onInput} onKeyPress={this.onKeyPress}/>; } diff --git a/src/components/keyfilter/KeyFilter.js b/src/components/keyfilter/KeyFilter.js index c51ae19d56..5a6b1a653f 100644 --- a/src/components/keyfilter/KeyFilter.js +++ b/src/components/keyfilter/KeyFilter.js @@ -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(); @@ -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; + } } \ No newline at end of file