Passing invalidate on onValidSubmit and onInvalidSubmit
This commit is contained in:
parent
fe8ec06af9
commit
5e00ea281f
|
|
@ -1,4 +1,6 @@
|
|||
.DS_Store
|
||||
build/index.html
|
||||
build/test.js
|
||||
build/formsy-react.js
|
||||
build/specs.js
|
||||
node_modules
|
||||
|
|
|
|||
14
README.md
14
README.md
|
|
@ -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
2039
build/specs.js
2039
build/specs.js
File diff suppressed because one or more lines are too long
17
src/main.js
17
src/main.js
|
|
@ -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';
|
||||
|
|
|
|||
Loading…
Reference in New Issue