From 355c0bbee31c4fddd5ba08d686e97121ee2ac714 Mon Sep 17 00:00:00 2001 From: Erwan Jegouzo Date: Tue, 21 Apr 2015 15:51:51 -0400 Subject: [PATCH 1/2] don't validate the inputs when the form was not submitted adding resetForm method --- src/Mixin.js | 6 +++++- src/main.js | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Mixin.js b/src/Mixin.js index 811cd74..3205efb 100644 --- a/src/Mixin.js +++ b/src/Mixin.js @@ -36,7 +36,8 @@ module.exports = { _isPristine: true, _pristineValue: this.props.value, _validationError: '', - _externalError: null + _externalError: null, + _formSubmitted: false }; }, getDefaultProps: function () { @@ -137,6 +138,9 @@ module.exports = { isPristine: function () { return this.state._isPristine; }, + isFormSubmitted: function () { + return this.state._formSubmitted; + }, isRequired: function () { return !!this.props.required; }, diff --git a/src/main.js b/src/main.js index cd95804..f6208b7 100644 --- a/src/main.js +++ b/src/main.js @@ -74,6 +74,11 @@ Formsy.Form = React.createClass({ }.bind(this), 0); }, + resetForm: function () { + this.setFormPristine(true); + this.resetModel(); + }, + // Update model, submit to url prop and send the model submit: function (event) { @@ -190,11 +195,16 @@ Formsy.Form = React.createClass({ var inputs = this.inputs; var inputKeys = Object.keys(inputs); + this.setState({ + _formSubmitted: !isPristine + }) + // Iterate through each component and set it as pristine // or "dirty". inputKeys.forEach(function (name, index) { var component = inputs[name]; component.setState({ + _formSubmitted: !isPristine, _isPristine: isPristine }); }.bind(this)); @@ -398,7 +408,7 @@ Formsy.Form = React.createClass({ return React.DOM.form({ onSubmit: this.submit, - className: this.props.className + className: this.props.className }, this.traverseChildrenAndRegisterInputs(this.props.children) ); From cf1550d4f2aad245959cb44960ea44342a7d0611 Mon Sep 17 00:00:00 2001 From: Michael Contento Date: Fri, 24 Apr 2015 18:43:35 +0200 Subject: [PATCH 2/2] Fix code example in API.md --- API.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/API.md b/API.md index 29d1155..2db16df 100644 --- a/API.md +++ b/API.md @@ -118,7 +118,7 @@ Whenever the form becomes valid the "onValid" handler is called. Use it to chang #### onInvalid() ```html - + ``` Whenever the form becomes invalid the "onInvalid" handler is called. Use it to for example revert "onValid" state.