Passing invalidate on onValidSubmit and onInvalidSubmit

This commit is contained in:
christianalfoni 2015-04-11 15:39:52 +02:00
parent fe8ec06af9
commit 5e00ea281f
5 changed files with 22 additions and 2692 deletions

2
.gitignore vendored
View File

@ -1,4 +1,6 @@
.DS_Store
build/index.html
build/test.js
build/formsy-react.js
build/specs.js
node_modules

View File

@ -28,6 +28,8 @@ In development you will get a warning about Formsy overriding `props`. This is d
- [onError()](#onerror)
- [onValid()](#onvalid)
- [onInvalid()](#oninvalid)
- [onValidSubmit()](#onvalidsubmit)
- [onInvalidSubmit()](#onvinalidsubmit)
- [onChange()](#onchange)
- [Formsy.Mixin](#formsymixin)
- [name](#name)
@ -294,6 +296,18 @@ Whenever the form becomes valid the "onValid" handler is called. Use it to chang
```
Whenever the form becomes invalid the "onInvalid" handler is called. Use it to for example revert "onValid" state.
#### <a name="onvalidsubmit">onValidSubmit(model, resetForm, invalidateForm)</a>
```html
<Formsy.Form url="/users" onValidSubmit={this.sendToServer}></Formsy.Form>
```
Triggers when form is submitted with a valid state. The arguments are the same as on `onSubmit`.
#### <a name="oninvalidsubmit">onInvalidSubmit(model, resetForm, invalidateForm)</a>
```html
<Formsy.Form url="/users" onInvalidSubmit={this.notifyFormError}></Formsy.Form>
```
Triggers when form is submitted with an invalid state. The arguments are the same as on `onSubmit`.
#### <a name="onchange">onChange(currentValues)</a>
```html
<Formsy.Form url="/users" onChange={this.saveCurrentValuesToLocalStorage}></Formsy.Form>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -86,24 +86,19 @@ Formsy.Form = React.createClass({
// so validation becomes visible (if based on isPristine)
this.setFormPristine(false);
// 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.
this.updateModel();
var model = this.mapModel();
this.props.onSubmit(model, this.resetModel, this.updateInputsWithError);
this.state.isValid ? this.props.onValidSubmit(model, this.resetModel, this.updateInputsWithError) : this.props.onInvalidSubmit(model, this.resetModel, this.updateInputsWithError);
if (!this.props.url) {
this.updateModel();
var model = this.mapModel();
this.props.onSubmit(model, this.resetModel, this.updateInputsWithError);
this.state.isValid ? this.props.onValidSubmit(model, this.resetModel) : this.props.onInvalidSubmit(model, this.resetModel);
return;
return;
}
this.updateModel();
this.setState({
isSubmitting: true
});
this.props.onSubmit(this.mapModel(), this.resetModel, this.updateInputsWithError);
var headers = (Object.keys(this.props.headers).length && this.props.headers) || options.headers || {};
var method = this.props.method && utils.ajax[this.props.method.toLowerCase()] ? this.props.method.toLowerCase() : 'post';