UNPKG

@42.nl/jarb-final-form

Version:
47 lines (46 loc) 1.71 kB
import { FieldProps } from '@42.nl/final-form-field-validation'; export type JarbProps = { validator: string; label: string; fractionalNumberRegex?: (fractionLength: number) => RegExp; }; export interface JarbFieldProps<FieldValue, T extends HTMLElement> extends FieldProps<FieldValue, T> { jarb: JarbProps; } /** * JarbField wraps final-form's Field, and adds the auto validation * from the constraints. In fact it is a very thin wrapper around * Field. * * It only demands one extra property called `jarb` which is used * to to configure the Field. The `jarb` object needs two keys: * the `validator` and the `label`. * * The `validator` follows the following format: `{Entity}.{Property}`. * For example if the validator property is 'SuperHero.name' this means that * the Field will apply the constraints for the 'name' property of * the `SuperHero` entity. * * The `label` is used to inform you which field was wrong, when errors occur. * You will receive the 'label' when an error occurs to create a nice * error message. * * It is also possible to add custom field validators and async validators * via the `validators` and `asyncValidators` props. The `asyncValidators` * are only ran when the all synchronous `validators` have declared the * field valid. * * See the documentation for some examples on how to create custom * validators. * * @example * ```JavaScript * <JarbField * name="Name" * jarb={{ validator: 'SuperHero.name', label: "Name" }} * component="input" * type="text" * /> * ``` */ export declare function JarbField<FieldValue, T extends HTMLElement>(props: JarbFieldProps<FieldValue, T>): import("react/jsx-runtime").JSX.Element;