diff --git a/API.md b/API.md index c356e15..2bbb8f1 100644 --- a/API.md +++ b/API.md @@ -35,6 +35,8 @@ - [isFormSubmitted()](#isformsubmitted) - [validate](#validate) - [formNoValidate](#formnovalidate) +- [Formsy.HOC](#formsyhoc) +- [Formsy.Decorator](#formsydecorator) - [Formsy.addValidationRule](#formsyaddvalidationrule) - [Validators](#validators) @@ -109,7 +111,7 @@ var Form = React.createClass({ ```html ``` -Takes a function to run when the submit button has been clicked. +Takes a function to run when the submit button has been clicked. The first argument is the data of the form. The second argument will reset the form. The third argument will invalidate the form by taking an object that maps to inputs. E.g. `{email: "This email is taken"}`. Resetting or invalidating the form will cause **setState** to run on the form element component. @@ -226,12 +228,12 @@ The message that will show when the form input component is invalid. It will be #### validationErrors ```html -showRequired() ```javascript @@ -424,7 +426,7 @@ var MyInput = React.createClass({ } }); ``` -Lets you check if the form input component should indicate if it is a required field. This happens when the form input component value is empty and the required prop has been passed. +Lets you check if the form input component should indicate if it is a required field. This happens when the form input component value is empty and the required prop has been passed. #### showError() ```javascript @@ -539,6 +541,41 @@ var MyInput = React.createClass({ }); ``` +### Formsy.HOC +The same methods as the mixin are exposed to the HOC version of the element component, though through the `props`, not on the instance. +```js +import {HOC} from 'formsy-react'; + +class MyInput extends React.Component { + render() { + return ( +
+ this.props.setValue(e.target.value)}/> +
+ ); + } +}; +export default HOC(MyInput); +``` + +### Formsy.Decorator +The same methods as the mixin are exposed to the decorator version of the element component, though through the `props`, not on the instance. +```js +import {Decorator as FormsyElement} from 'formsy-react'; + +@FormsyElement() +class MyInput extends React.Component { + render() { + return ( +
+ this.props.setValue(e.target.value)}/> +
+ ); + } +}; +export default MyInput +``` + ### Formsy.addValidationRule(name, ruleFunc) An example: ```javascript