From f1d9d6c15c7946544d26050b0a00484bea0d0f79 Mon Sep 17 00:00:00 2001 From: christianalfoni Date: Fri, 3 Apr 2015 13:25:04 +0200 Subject: [PATCH] Added section on validate method --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index 9173b0b..c117e13 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