don't validate the inputs when the form was not submitted

adding resetForm method
This commit is contained in:
Erwan Jegouzo 2015-04-21 15:51:51 -04:00
parent b18b4e8c79
commit 355c0bbee3
2 changed files with 16 additions and 2 deletions

View File

@ -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;
},

View File

@ -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)
);