Merge pull request #5 from LaustAxelsen/patch-1
Allow for no url, using "onSubmit" handler to pass model for manual XHR
This commit is contained in:
commit
32f67e24ac
14
src/main.js
14
src/main.js
|
|
@ -196,8 +196,13 @@ Formsy.Form = React.createClass({
|
|||
submit: function (event) {
|
||||
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"},
|
||||
// if wanting to reset the entire form to original state, the second param is a callback for this.
|
||||
if (!this.props.url) {
|
||||
throw new Error('Formsy Form needs a url property to post the form');
|
||||
this.updateModel();
|
||||
this.props.onSubmit(this.model, this.resetModel);
|
||||
return;
|
||||
}
|
||||
|
||||
this.updateModel();
|
||||
|
|
@ -225,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
|
||||
|
|
|
|||
Loading…
Reference in New Issue