diff --git a/README.md b/README.md index 9173b0ba..c117e132 100644 --- a/README.md +++ b/README.md @@ -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(); ``` You can now disable the form itself with a prop and use **isFormDisabled()** inside form elements to verify this prop. +#### validate +```javascript +var MyInput = React.createClass({ + mixins: [Formsy.Mixin], + changeValue: function (event) { + this.setValue(event.target.value); + }, + validate: function () { + return !!this.getValue(); + }, + render: function () { + return ( +
+ +
+ ); + } +}); + +React.render(); +``` +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. + ### Formsy.addValidationRule(name, ruleFunc) An example: ```javascript