apphouse
Version:
Component library for React that uses observable state management and theme-able components.
75 lines (74 loc) • 1.89 kB
TypeScript
import { InputProps } from '../../components/input/input.interface';
import { FieldType, FormFieldOptions, FormFieldType } from './Field.interface';
/**
* A model to represent a field in a form.
*/
export declare class Field {
/**
* The id of the field. It must be unique for the form.
*/
id: string;
/**
* The value of the field.
*/
value: string | undefined;
/**
* The type of the field.
* @default 'text'
*/
type: FormFieldType;
/**
* Options for the field if the field is of type `option`.
*/
options?: FormFieldOptions;
/**
* The prop options for the input component.
*/
input?: Partial<InputProps>;
/**
* A function to validate the value of the field.
* @optional Defaults will be used if not provided.
*/
validation?: (value?: string) => boolean;
constructor(props: FieldType);
/**
* Whether the field is valid or not.
*/
get valid(): boolean;
/**
* Sets the value of the field.
* @param value the value to set the field to
*/
set: (value?: string) => void;
/**
* Sets the input to be disabled
* @param disabled
*/
setDisabled: (disabled: boolean) => void;
/**
* Sets the input to be required
* @param required
*/
setRequired: (required: boolean) => void;
/**
* Sets the min value of input
* *Only applies to number, date, input types*
* @param min
*/
setMin: (min: string) => void;
/**
* Sets the max value of input
* *Only applies to number, date, input types*
* @param min
*/
setMax: (max: string) => void;
/**
* Clears the value of the field.
*/
clear: () => void;
/**
* Get the field as a plain object.
* @returns the field as a plain object
*/
obj: () => FieldType;
}