UNPKG

vue-forms-builder

Version:

Typescript forms builder package written specifically for Vue

104 lines (103 loc) 3.16 kB
import { ValidationError, ValidatorFunction } from '../models'; export declare class FormControl { private _value; private _defaultValue; private _validators; touched: boolean; valid: boolean; error: ValidationError; /** * Setter for the control value * @memberof FormControl */ set value(value: any); /** * Getter for the control value * @type {*} * @memberof FormControl */ get value(): any; /** * Initialize the FormControl instance * @param value - value for the control * @param validators - validator or array of validators for the control */ constructor(value: any, validators?: ValidatorFunction[] | ValidatorFunction); /** * Sets a new value for the control * @param value - new value */ setValue(value: any): void; /** * Patches the value of the control * @param value - new value */ patchValue(value: any): void; /** * Marks the control as touched */ markAsTouched(): void; /** * Marks the control as touched */ markAllAsTouched(): void; /** * Marks the control as untouched */ markAsUntouched(): void; /** * Sets validators to this control * If it has any validators, they will be overwritten * @param validators - new validator or array of validators */ setValidators(validators: ValidatorFunction | ValidatorFunction[]): void; /** * Add validators to this control * If it has any validators, they will be added to the existing ones * @param validators - new validator or array of validators */ addValidators(validators: ValidatorFunction | ValidatorFunction[]): void; /** * Removes validators from this control * @param validators - validator or array of validators to be removed */ removeValidators(validators: ValidatorFunction | ValidatorFunction[]): void; /** * Checks if validator exist in this control * @param validators - validator to check * @returns if validator exist returns true, if not returns false */ hasValidator(validator: ValidatorFunction): boolean; /** * Removes all validators from this control */ clearValidators(): void; /** * Sets error to this control * It also set validation to be falsy * @param error - error to be set */ setError(error: ValidationError): void; /** * Checks if the control have specified error * @param error - name of error * @returns if error exist returns true, if not returns false */ hasError(error: string): boolean; /** * Resets the control to the initial value, * setting it as untouched, resetting error * and setting validators to the initial value */ reset(): void; /** * Private method that checks if the control is valid * and setting error and control validity */ private _validateControl; /** * Private method for removing validator from the control * @param validator - validator to be removed */ private _removeValidator; }