jarb-redux-form
Version:
Validating forms through JaRB.
56 lines (54 loc) • 2.06 kB
TypeScript
import { Component, ComponentType } from 'react';
import { BaseFieldProps, WrappedFieldProps } from 'redux-form';
import { RequiredValidator, MinimumLengthValidator, MaximumLengthValidator, MinValueValidator, MaxValueValidator, PatternValidator } from './validators';
export interface JarbProps {
validator: string;
label: string;
}
export interface JarbFieldProps<P> extends BaseFieldProps<P> {
jarb: JarbProps;
component?: ComponentType<WrappedFieldProps & P>;
}
/**
* JarbField wrappes redux-form's Field, and adds the auto validation
* from the ConstraintsStore. 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.
*
* @example
* ```JavaScript
* <JarbField
* name="Name"
* jarb={{ validator: 'SuperHero.name', label: "Name" }}
* component="input"
* type="text"
* />
* ```
*
* @export
* @param {Props.name} name The name of the field, must have the following format: {Entity}.{Property}
* @param {Props.jarb} object Object containing the 'label' and 'validator'.
* @returns
*/
export declare class JarbField<P> extends Component<JarbFieldProps<P>> {
requiredValidator: RequiredValidator | null;
minimumLengthValidator: MinimumLengthValidator | null;
maximumLengthValidator: MaximumLengthValidator | null;
minValueValidator: MinValueValidator | null;
maxValueValidator: MaxValueValidator | null;
patternValidator: PatternValidator | null;
getEnhancedValidate(): Function[];
render(): JSX.Element;
}