From 22892909985290d47b783010423f21d036d8618a Mon Sep 17 00:00:00 2001 From: LaustAxelsen Date: Tue, 6 Jan 2015 22:08:44 +0100 Subject: [PATCH] Update main.js Added a resetModel method which is also passed to the onSubmit callback. --- src/main.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main.js b/src/main.js index 26cd4de..f1d16eb 100644 --- a/src/main.js +++ b/src/main.js @@ -197,10 +197,11 @@ Formsy.Form = React.createClass({ event.preventDefault(); // To support use cases where no async or request operation is needed. - // The "onSubmit" callback is called with the model e.g. {fieldName: "myValue"} + // The "onSubmit" callback is called with the model e.g. {fieldName: "myValue"}, + // if wanting to reset the entire form to original state, the second param is a callback for this. if (!this.props.url) { this.updateModel(); - this.props.onSubmit(this.model); + this.props.onSubmit(this.model, this.resetModel); return; } @@ -229,6 +230,13 @@ Formsy.Form = React.createClass({ this.model[name] = component.state._value; }.bind(this)); }, + + // Reset each key in the model to the original / initial value + resetModel: function() { + Object.keys(this.inputs).forEach(function (name) { + this.inputs[name].resetValue(); + }.bind(this)); + }, // Go through errors from server and grab the components // stored in the inputs map. Change their state to invalid