UNPKG

@mobx-ecosystem/mobx-form

Version:

provides the ability to use forms with validation in MobX stores

86 lines (85 loc) 2.45 kB
import { FormErrors, FormServiceValuesType, FormValues, IForm, KeyParams, MethodOptions, ValidationType, ValueType } from './types'; export declare class FormService<T extends FormServiceValuesType> implements IForm<T> { fields: T; validationSchema?: unknown; onSubmit?: () => Promise<unknown>; constructor(fields: T, validationSchema?: unknown); setOnSubmit: (onSubmit: () => Promise<unknown>) => void; submit: () => Promise<unknown>; /*** * Validate the form * * *Configure this method with configureForm from mobx-form */ validate: (type?: ValidationType) => Promise<void>; setValidationSchema: (validationSchema: unknown) => void; /** * Return field keys */ get keys(): string[]; /** * Check each field if its isValid = true */ get isValid(): boolean; /** * Check each field if its isTouched = true */ get isTouched(): boolean; /** * Check if isTouched = true && isValid = true */ get canBeSubmitted(): boolean; /** * always true if the form service is empty */ get disabled(): boolean; /** * * @returns Object of field values */ getValues: () => FormValues<ValueType<T>>; private getValue; /** * Set fields by this */ setFieldsByThis: (obj: any) => void; private bypassFields; private setValidationToFields; /** * Set object to init values by form service keys */ setInitValues: (values: Partial<FormValues<T>>, { validate }?: { validate?: boolean | undefined; }) => void; /** * Set object to values by form service keys */ setValues: (values: Partial<FormValues<T>>, { validate }?: MethodOptions) => void; /** * Set field errors to undefined */ resetErrors: () => void; /** * Set errors for fields * @param errors object of string which provides errors for fields */ setErrors(error: Partial<FormErrors<T>>, validationType?: ValidationType): void; /** * Set field values to init values */ setValuesAsInit: () => void; private getKeys; /** * Reset fields to their own initial values */ reset: (keyParams?: KeyParams<keyof T>) => void; /** * Pass true to the property 'disabled' */ disable: () => void; /** * Pass false to the property 'disabled' */ enable: () => void; touch: () => void; }