A lightweight react form validation library for functional programming.
npm install react-form-validation-contextA lightweight react form validation library that uses HOCs (higher order components) for functional programming, with typescript support.

```
yarn add react-form-validation-context
Or
``
npm install --save react-form-validation-context
`javascript `
import {
Form,
withForm,
validators,
withFormButton,
FormErrors // Optional, for custom errors
} from "react-form-validation-context";
withForm is a higher order component that can wrap any kind of user input.
Below are some examples of how to create some form connected components
#### Text inputs
Javascript
`javascript`
const Input = withForm(({ value, onChange, error, showErrors }) => (
onChange(v)} value={value} />
{showErrors && error && {error}}
));
Typescript
`javascript
export const InputComponent: React.SFC
value,
onChange,
error,
showErrors
}: any) => (
{showErrors && error && {error}}
);
const Input = withForm(InputComponent);
`
#### Select options
Javascript
`javascript`
const Dropdown = withForm(
({ value, onChange, error, showErrors, options}) => (
{showErrors && error && {error}}
)
);
Typescript
`javascript
export const DropdownComponent: React.SFC
value,
onChange,
error,
showErrors,
options
}: any) => (
{showErrors && error && {error}}
);
const Dropdown = withForm(DropdownComponent);
`
#### Radio buttons
Javascript
`javascript`
const Radios = withForm(
({ value, onChange, error, showErrors, options, id }) => (
{options.map(({ label, val }) => (
type="radio"
onChange={() => onChange(val)}
name={id}
checked={value === val}
/>
))}
{showErrors && error && {error}}
)
);
` return (javascript
export const RadioComponent: React.SFC
value,
onChange,
error,
showErrors,
options,
id
}: any) => (
{options.map(({ label, val }: { label: string; val: string }) => {
const handleChange = () => onChange(val);
type="radio"
onChange={handleChange}
name={id}
checked={value === val}
/>
);
})}
{showErrors && error && {error}}
);
const Radios = withForm(RadioComponent);
`
withFormButton is a higher order component that can a submit or action button
Javascript
`javascript`
const Button = withFormButton(({ children, ...rest }) => (
));
Typescript
`javascript
const ButtonComponent: React.SFC
);
const Button = withFormButton(ButtonComponent);
`
Errors will be passed to the components by default.
To suppress inline errors you can add the prop hideErrors.
For example:
`Javascript`
You can use the FormErrors component to display errors for specific components or for all errors on the form.
`javascript
// use a custom renderer
{error}
)}
/>
`
validators contain a set of validators for performing input validations
validators.requiredWithMessagevalidators.requiredvalidators.emailvalidators.maxLengthvalidators.minLengthvalidators.exactLengthvalidators.minValuevalidators.maxValuevalidators.maxFloatValuevalidators.decimalWithDotvalidators.numbervalidators.decimalWithCommaDotvalidators.nationalInsurancevalidators.alphaNumeric2WithMessagevalidators.alphaNumeric2validators.onlyAlphaNumericvalidators.addressvalidators.postcodevalidators.allowedValuesvalidators.stringMatchvalidators.passwordStrength
`javascript
class App extends Component {
state = {
name: "",
email: ""
};
submit() {
console.log(this.state);
}
render() {
return (
``
Dave Nicholas, Martin Carder, Ekta Wadhwani, Mariana Nicholas