react-input-error-validation
A basic input validation HOC to provide error validations around the input. You can pass in number of validators and do error handling every input wise. Hack in to refs to get complete Form Validations.
Usage
Try Running the demo for interative usage
import React Component from 'react'import withValidations from 'react-input-error-validation' // Create any input field. All props are required// Class based to support inputRef { const inputRef validations error checkValidations config ...rest = thisprops return <div> <input /> resterror && <div>resterror</div> </div> } // Applying HOCconst ValidatedTextField = /*Validations - It will take in the value prop from the input field as well and and `config` prop if passed. The config prop can be used to do extra checking like in the case of fixDigits. */const notEmpty = { if !val return 'Field Cannot Be Empty' return} const onlyNumber = { const pattern = /^\d+$/ if !pattern return 'Please Enter a Valid Number' return} // You can use config object to check for any custom configurations. const fixDigits = val config = if vallength !== configdigits return `Content should be only` return // Utility function to check for complete form errorsconst checkForErrors = { let err = false let errField = '' // this will contain the "name" of the "FIRST" field with error. Object // Keeping error field is optional and depends on the use case, // there may be a case where you want to take the users to the field where the error occoured. return err errField } // Finally we render it out. el = state = first: '' second: '' third: '' { const err = // passing el if !err console // Do Something here.... else console } { return <div> Must be filled : <ValidatedTextField = = = = // /> <br /> Should be a number and filled: <ValidatedTextField = = = = /> <br /> Number 7 digits and filled: <ValidatedTextField = = = = // . = // /> <br /> <input ="button" ="submit" = /> </div> }