diff --git a/package.json b/package.json index 0089653..8fb3cd9 100644 --- a/package.json +++ b/package.json @@ -49,4 +49,4 @@ "validator": "^3.41.3", "react-addons-create-fragment": "^0.14.7" } -} +} \ No newline at end of file diff --git a/src/Form.js b/src/Form.js index 3a27772..5d3b4fb 100644 --- a/src/Form.js +++ b/src/Form.js @@ -150,6 +150,13 @@ export default class Form extends InputContainer { _validateInput(name) { this._validateOne(name, this.getValues()); + + if (typeof this.props.validateAllCallback === 'function') { + let values = this.getValues(); + let { isValid } = this._validateAll(values, false); + + this.props.validateAllCallback(isValid); + } } _hasError(iptName) { @@ -175,7 +182,7 @@ export default class Form extends InputContainer { }); } - _validateOne(iptName, context) { + _validateOne(iptName, context, setError = true) { let input = this._inputs[iptName]; if (Array.isArray(input)) { @@ -210,12 +217,14 @@ export default class Form extends InputContainer { } } - this._setError(iptName, !isValid, error); + if (setError) { + this._setError(iptName, !isValid, error); + } return isValid; } - _validateAll(context) { + _validateAll(context, setError = true) { let isValid = true; let errors = []; @@ -233,7 +242,7 @@ export default class Form extends InputContainer { } } else { Object.keys(this._inputs).forEach(iptName => { - if (!this._validateOne(iptName, context)) { + if (!this._validateOne(iptName, context, setError)) { isValid = false; errors.push(iptName); } @@ -331,6 +340,7 @@ Form.propTypes = { onInvalidSubmit: React.PropTypes.func, validateOne : React.PropTypes.func, validateAll : React.PropTypes.func, + validateAllCallback: React.PropTypes.func, validationEvent: React.PropTypes.oneOf([ 'onChange', 'onBlur', 'onFocus' ]),