0.5.0 • Published 8 years ago
react-validation-tiny v0.5.0
React-validation-tiny
React js simple form validation. This is a very light react frontend validation module which uses
textarea, input tags as the text containers. It can also handle asynchronous validations :twisted_rightwards_arrows:
Install
$ npm install react-validation-tiny -sDocumentation:
This module is based on three components <Form> Beautiful children here </Form>, <Input /> and <TextArea />
<Form />Has to be a parent of Input/TextArea, not necessary the first.<Input /><TextArea />
For styling, just use the style prop
Props:
<Form />
onSubmitis of type function and will run after all theInputvalidators are done, then it will send back some parameters to tell you about what happend.ethe submit eventsuccessistrueif all the validations passed, otherwisefalse.formDataall the data from all the Inputs and TextAreas.failMessages?nullif success otherwise it will be anobjectwith arrays of fail. messages.
classNameis the reactclassNameof the form, default is'classic1'childrento be validated.
failMessages example:
{
numberoflife: ['Number should be of length 10', 'Potatos is not a number'],
}Props table
| Attributes | Type | Default | Description |
|---|---|---|---|
onSubmit | function | void | The function to run after validating the inputs |
className | string | 'classic1' | class name |
<Input /> and <TextArea />
namea string which can be used as an index, or even a namespace for inputs with same categories.nameis used to index thefaileMessageof an input in thefailMessagesobject.- All inputs with the same name will be in the same array.
maxthe max number of characters constraint.minthe min number of characters constraint.validationFailMessagea string which you can use as an index or messagee.g"Phone number does not have charecters"or whatever you want. It will basicly be one one of thefailMessagesin theonSubmitfailMessagesparameter.regexToMatchthe pattern the text must match to succeed.regexNotToMatchthe pattern that the text must never match.customValidationA COOL function which you can add to check the input in your own way, it will have two parameters:Inputvalue.nextwhich is a callback that you should run when your custom validation is done and send it a parameter oftrueif success otherwisefalse.
requireddefaulttruetypeis the type of the input.valuethe initial value, if you want that.onChangeValidationa callback that will run every time you make a change in the input field, the interval is defaulted to 1 second, it is restarted for every input.sucess,trueif validation succeededfailmessage?nullif succeededname, the name of the inputvalue, the value of the input
onChangeValidationIntervalthe interval foronChangeValidation, defaults to 1 second.
Props table
| Attributes | Type | Default | Description |
|---|---|---|---|
name | string | 'fieldx'+Date.now() | name of the field |
style | style | null | Button container custom styles |
max | number | 1000 | Maximum length |
min | number | -1000 | Minimum length |
regexToMatch | string | '.*' | Pattern should be matched |
regexNotToMatch | string | '?!.*' | Pattern should not have a match |
customValidation | function | void | Custom async validation |
required | bool | true | required HTML5 |
type | string | 'text' | Input type in HTML5 |
value | string | '' | Initial value |
onChangeValidation | function | null | every change validation callback |
onChangeValidationInterval | number | 1000 | The interval for onChangeValidation |
className | string | 'claasic2' | The class name |
validationFailMessage | string | 'Failed' | The message which tells you what failes |