import {Form} from "antd-mobile"; import {type Unboxed} from "../interface"; import {type INavigate} from "../router"; import { type IFormError, type IFormErrors, type INamePath } from "./form"; export interface IMobileFormItemContext { readonly field: INamePath; readonly label: string; setValue(value: any): void; getValue(): any; setErrors(errors: string[]): void; } export interface IMobileFormSuccess { /** * Handy shortcut for navigation. */ readonly navigate: INavigate; /** * Original values sent to the form. */ readonly values: TFormValues; /** * Response values got after processing form. */ readonly response: TResponse; /** * Access to the whole form context. */ readonly formContext: IMobileFormContext; /** * Translates given string using form's translation base if provided. * @param text * @param data */ t(text: string, data?: Record): string; } export interface IMobileFormContext { readonly translation?: string; readonly isSubmitVisible: boolean; /** * Antd form instance. */ readonly form: Unboxed>; /** * Set form values * * @param values values being set */ setValues(values: TValues): void; setValue(value: { name: INamePath, value: any }[]): void; /** * Set field errors. * * @param errors */ setErrors(errors: IFormErrors): void; /** * Reset form to the initial state. */ reset(): void; /** * Return current form values. */ values(): any; /** * Just a flag for form to show/hide submit button. Useful for example in tabbed forms where submit may not be visible all the times). * * @param show */ showSubmit(show: boolean): void; } export interface IMobileFormValuesChanged { readonly values: TFormValues; readonly formContext: IMobileFormContext; readonly changed: Partial; } export interface IMobileFormChanged { readonly values: TFormValues; readonly formContext: IMobileFormContext; } export interface IMobileFormFailure { readonly error: string; readonly formContext: IMobileFormContext; } export interface IToMobileFormError { readonly error: TError; readonly formContext: IMobileFormContext; } export interface IMobileErrorHandler { readonly error: TError; readonly formContext: IMobileFormContext; } export type IMobileFormErrorHandler = (error: IMobileErrorHandler) => void; export type IMobileFormErrorMap = Record>