1.6.1 • Published 7 years ago

react-awesome-form-validator-react16 v1.6.1

Weekly downloads
1
License
ISC
Repository
github
Last release
7 years ago

Damian Aruj · CircleCI Status Build Status npm version

React Awesome Form Validation

This library is a simple solution of a common issue with forms with custom validations using ReactJs. It lets you use a pre-defined Input or even create your custom one with all it needs to be part of the same form.

Examples

Simple Form: Code Here

  • run: npm run simple-form

Form with custom Input: Code Here, Custom Input

  • run: npm run form-with-custom-input

Form with reset and clear values: Code Here

  • run: npm run form-with-reset-and-clear-values

Then open a browser and type: http://localhost:3000

Form Props:

NameTypeDefaultDescriptionRequired
childrennode/string-Form inputs or other html tags or strings-
classNamestring''Form classNamefalse
resetFormboolean-if true will reset the form of default values. In order to use this prop you need to add formWasReset too.false
formWasResetfunction-Function to be called right after we reset the form. The idea of this prop is to change the 'resetForm' prop to false again. example: formWasReset={() => this.setState({ resetForm: false })}false
onSubmitfunction-When the user clicks on the SubmitButton and all the validations pass, it will call this method and it will pass an object with all the form's inputs values.true
onResetfunction-When the user clicks on the ResetButton and all the validations pass, it will call this method and it will reset the form values.false
disableInputsboolean-If true it will disable all fields. This prop is very useful for when we call the onSubmit method.false
clearValuesOnResetboolean-If True it will reset and clear all valuesfalse
serverErrorsobject-Object to display errors from the server. example: serverErrors={{ email: 'This email exist, please use another one' }}false

Input Props:

NameTypeDefaultDescriptionRequired
typestringtextInput typetrue
namestring-Input name and reftrue
placeHolderstring-Input PlaceHolderfalse
labelstring-Label to be displayed within the inputfalse
customLabelnode-Label to be displayed within the inputfalse
startValidatingWhenIsPristinebooleanfalseif true the input will start validating immediately as you start typingfalse
classNamestring''Input classNamefalse
fieldClassNamestring''Every Input comes wrapped with a div. This is the div classNamefalse
invalidClassNamestring''className for the input when does not pass its validationsfalse
onChangefunction-We store internally on this library every input value and when you click on the SubmitButton and you pass all the validations it will call the method provided on the SubmitButton and it will pass an object with all the input values. Let's say you need to do something with the input value before the user clicks on SubmitButton, then you can get the its value with this prop.false
onBlurfunction-Same as onChangefalse
validatefunction-You have to return an object with the following structure: { valid, errorMessage } where valid is a boolean and errorMessage is a string.false
serverValuestring''Value coming from the serverfalse
readOnlyboolfalseif true will set the input as read onlyfalse

SubmitButton Props:

NameTypeDefaultDescriptionRequired
childrennode/string-Button texttrue
classNamestring''Button classNamefalse
fieldClassNamestring''This Button comes wrapped with a div. This is the div classNamefalse
disabledUntilFormIsValidatedbooleanfalseIt will disable the button until all fields are validfalse

CustomSubmitButton Props:

NameTypeDefaultDescriptionRequired
childrennode/string-Submit Buttontrue

ResetButton Props:

NameTypeDefaultDescriptionRequired
childrennode/string-Button texttrue
classNamestring''Button classNamefalse
fieldClassNamestring''This Button comes wrapped with a div. This is the div classNamefalse
clearValuesboolean-If True it will reset and clear all valuesfalse

CustomResetButton Props:

NameTypeDefaultDescriptionRequired
childrennode/string-Reset Buttontrue
clearValuesboolean-If True it will reset and clear all valuesfalse

Hope you enjoy it!