set of validators to use with final-form or redux-form
yarn add final-form-validations
import React, { Component } from "react";
import { Form, Field } from "rect-final-form";
import {
createValidator,
composeFieldValidators,
required,
minLength,
maxLength,
lessOrEqual,
} from "@dmitry.olyenyov/final-form-validations";
const validators = createValidator({
lastName: [
requried("Required!"),
minLength(2, "Please enter at least 2 chars"),
maxLength(500, "Name is too long"),
],
description: required("Required!"),
});
class Example extends Component {
render() {
return (
<Form onSubmit={() => {}} validate={validators}>
<Field name="lastName" component="input" />
<Field name="description" component="input" />
<Field
name="someField"
component="input"
validate={composeFieldValidators(
required("Required!"),
lessOrEqual(1000, "Must be less than 1000")
)}
/>
</Form>
);
}
}
MIT © Dema