@cosva-lab/form-builder
Version:
React form builder.
120 lines (119 loc) • 4.07 kB
TypeScript
import type { ValidationErrors, OnSetValue, OnChangeField, LabelPropsField, TypeField, PropsFieldBase, NameField } from '../../types';
import { StatusField } from '../../enums';
import { GenericFieldsBuilder } from '../../types';
export declare class Field<V, Name extends NameField, Label extends LabelPropsField> implements PropsFieldBase<V, Name, Label> {
fieldsBuilder?: GenericFieldsBuilder;
type?: TypeField;
name: Name;
value: V;
defaultInputValue?: V;
label: Label;
status?: StatusField;
errors?: ValidationErrors;
inputRef?: HTMLInputElement | null;
onChange?: OnChangeField<V, Name, Label>;
onSetValue?: OnSetValue<V, Name, Label>;
pristine: boolean;
/**
* A control is `dirty` if the user has changed the value
* in the UI.
*
* @returns True if the user has changed the value of this control in the UI; compare `pristine`.
* Programmatic changes to a control's value do not mark it dirty.
*/
get dirty(): boolean;
/**
* A control is `valid` when its `status` is `VALID`.
*
* @see {@link Field.status}
*
* @returns True if the control has passed all of its validation tests,
* false otherwise.
*/
get valid(): boolean;
/**
* A control is `invalid` when its `status` is `INVALID`.
*
* @see {@link Field.status}
*
* @returns True if this control has failed one or more of its validation checks,
* false otherwise.
*/
get invalid(): boolean;
/**
* A control is `pending` when its `status` is `PENDING`.
*
* @see {@link Field.status}
*
* @returns True if this control is in the process of conducting a validation check,
* false otherwise.
*/
get pending(): boolean;
/**
* A control is `disabled` when its `status` is `DISABLED`.
*
* Disabled controls are exempt from validation checks and
* are not included in the aggregate value of their ancestor
* controls.
*
* @see {@link Field.status}
*
* @returns True if the control is disabled, false otherwise.
*/
get disabled(): boolean;
/**
* A control is `enabled` as long as its `status` is not `DISABLED`.
*
* @returns True if the control has any status other than 'DISABLED',
* false if the status is 'DISABLED'.
*
* @see {@link Field.status}
*
*/
get enabled(): boolean;
/**
* Disables the control. This means the control is exempt from validation checks and
* excluded from the aggregate value of any parent. Its status is `DISABLED`.
*
* If the control has children, all children are also disabled.
*
* @see {@link Field.status}
*/
disable(): void;
/**
* Enables the control. This means the control is included in validation checks and
* the aggregate value of its parent. Its status recalculates based on its value and
* its validators.
*
* By default, if the control has children, all children are enabled.
*
* @see {@link Field.status}
*/
enable(): void;
/**
* Marks the control as `dirty`. A control becomes dirty when
* the control's value is changed through the UI; compare `markAsTouched`.
*
* @see `markAsTouched()`
* @see `markAsUntouched()`
* @see `markAsPristine()`
*
*/
markAsDirty(): void;
/**
* Marks the control as `pristine`.
*
* If the control has any children, marks all children as `pristine`,
* and recalculates the `pristine` status of all parent
* controls.
*
* @see `markAsTouched()`
* @see `markAsUntouched()`
* @see `markAsDirty()`
*
*/
markAsPristine(): void;
_setInitialStatus(): void;
constructor({ type, name, value, disabled, defaultInputValue, label, onChange, onSetValue, }: PropsFieldBase<V, Name, Label>);
}
export default Field;