Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
christianalfoni committed May 22, 2015
2 parents 23f91c4 + 9950043 commit dbb0653
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ Formsy.Form = React.createClass({
},

componentWillUpdate: function () {

// Keep a reference to input keys before form updates,
// to check if inputs has changed after render
this.prevInputKeys = Object.keys(this.inputs);

},

componentDidUpdate: function () {

if (this.props.validationErrors) {
this.setInputValidationErrors(this.props.validationErrors);
}
Expand All @@ -70,9 +70,10 @@ Formsy.Form = React.createClass({

},

reset: function () {
// Allow resetting to specified data
reset: function (data) {
this.setFormPristine(true);
this.resetModel();
this.resetModel(data);
},

// Update model, submit to url prop and send the model
Expand Down Expand Up @@ -104,10 +105,14 @@ Formsy.Form = React.createClass({
}.bind(this));
},

// Reset each key in the model to the original / initial value
resetModel: function () {
// Reset each key in the model to the original / initial / specified value
resetModel: function (data) {
Object.keys(this.inputs).forEach(function (name) {
this.inputs[name].resetValue();
if (data && data[name]) {
this.inputs[name].setValue(data[name]);
} else {
this.inputs[name].resetValue();
}
}.bind(this));
this.validateForm();
},
Expand Down

0 comments on commit dbb0653

Please sign in to comment.