Merge branch 'master' of https://github.com/christianalfoni/formsy-react
This commit is contained in:
commit
accc0815db
2
API.md
2
API.md
|
|
@ -120,7 +120,7 @@ Whenever the form becomes valid the "onValid" handler is called. Use it to chang
|
|||
|
||||
#### <a name="oninvalid">onInvalid()</a>
|
||||
```html
|
||||
<Formsy.FormonInvalid={this.disableSubmitButton}></Formsy.Form>
|
||||
<Formsy.Form onInvalid={this.disableSubmitButton}></Formsy.Form>
|
||||
```
|
||||
Whenever the form becomes invalid the "onInvalid" handler is called. Use it to for example revert "onValid" state.
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,8 @@ module.exports = {
|
|||
_isPristine: true,
|
||||
_pristineValue: this.props.value,
|
||||
_validationError: '',
|
||||
_externalError: null
|
||||
_externalError: null,
|
||||
_formSubmitted: false
|
||||
};
|
||||
},
|
||||
getDefaultProps: function () {
|
||||
|
|
@ -138,6 +139,9 @@ module.exports = {
|
|||
isPristine: function () {
|
||||
return this.state._isPristine;
|
||||
},
|
||||
isFormSubmitted: function () {
|
||||
return this.state._formSubmitted;
|
||||
},
|
||||
isRequired: function () {
|
||||
return !!this.props.required;
|
||||
},
|
||||
|
|
|
|||
12
src/main.js
12
src/main.js
|
|
@ -74,6 +74,11 @@ Formsy.Form = React.createClass({
|
|||
}.bind(this), 0);
|
||||
},
|
||||
|
||||
resetForm: function () {
|
||||
this.setFormPristine(true);
|
||||
this.resetModel();
|
||||
},
|
||||
|
||||
// Update model, submit to url prop and send the model
|
||||
submit: function (event) {
|
||||
|
||||
|
|
@ -190,11 +195,16 @@ Formsy.Form = React.createClass({
|
|||
var inputs = this.inputs;
|
||||
var inputKeys = Object.keys(inputs);
|
||||
|
||||
this.setState({
|
||||
_formSubmitted: !isPristine
|
||||
})
|
||||
|
||||
// Iterate through each component and set it as pristine
|
||||
// or "dirty".
|
||||
inputKeys.forEach(function (name, index) {
|
||||
var component = inputs[name];
|
||||
component.setState({
|
||||
_formSubmitted: !isPristine,
|
||||
_isPristine: isPristine
|
||||
});
|
||||
}.bind(this));
|
||||
|
|
@ -398,7 +408,7 @@ Formsy.Form = React.createClass({
|
|||
|
||||
return React.DOM.form({
|
||||
onSubmit: this.submit,
|
||||
className: this.props.className
|
||||
className: this.props.className
|
||||
},
|
||||
this.traverseChildrenAndRegisterInputs(this.props.children)
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in New Issue