Added section on validate method

This commit is contained in:
christianalfoni 2015-04-03 13:25:04 +02:00
parent 0964b07e1d
commit f1d9d6c15c
1 changed files with 24 additions and 0 deletions

View File

@ -42,6 +42,7 @@ A form input builder and validator for React JS
- [showError()](#showerror)
- [isPristine()](#ispristine)
- [isFormDisabled()](#isformdisabled)
- [validate](#validate)
- [Formsy.addValidationRule](#formsyaddvalidationrule)
- [Validators](#validators)
@ -565,6 +566,29 @@ React.render(<Formy.Form disabled={true}/>);
```
You can now disable the form itself with a prop and use **isFormDisabled()** inside form elements to verify this prop.
#### <a name="validate">validate</a>
```javascript
var MyInput = React.createClass({
mixins: [Formsy.Mixin],
changeValue: function (event) {
this.setValue(event.target.value);
},
validate: function () {
return !!this.getValue();
},
render: function () {
return (
<div>
<input type="text" value={this.getValue()} onChange={this.changeValue}/>
</div>
);
}
});
React.render(<Formy.Form disabled={true}/>);
```
You can create custom validation inside a form element. The validate method defined will be run when you set new values to the form element. It will also be run when the form validates itself. This is an alternative to passing in validation rules as props.
### <a name="formsyaddvalidationrule">Formsy.addValidationRule(name, ruleFunc)</a>
An example:
```javascript