UNPKG

@conform-to/dom

Version:

A set of opinionated helpers built on top of the Constraint Validation API

44 lines (43 loc) 1.81 kB
/** * Element that user can interact with, * includes `<input>`, `<select>` and `<textarea>`. */ export type FieldElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement; /** * HTML Element that can be used as a form control, * includes `<input>`, `<select>`, `<textarea>` and `<button>`. */ export type FormControl = FieldElement | HTMLButtonElement; /** * Form Control element. It can either be a submit button or a submit input. */ export type Submitter = HTMLInputElement | HTMLButtonElement; /** * A type guard to check if the provided element is a form control */ export declare function isFormControl(element: unknown): element is FormControl; /** * A type guard to check if the provided element is a field element, which * is a form control excluding submit, button and reset type. */ export declare function isFieldElement(element: unknown): element is FieldElement; /** * Resolves the action from the submit event * with respect to the submitter `formaction` attribute. */ export declare function getFormAction(event: SubmitEvent): string; /** * Resolves the encoding type from the submit event * with respect to the submitter `formenctype` attribute. */ export declare function getFormEncType(event: SubmitEvent): 'application/x-www-form-urlencoded' | 'multipart/form-data'; /** * Resolves the method from the submit event * with respect to the submitter `formmethod` attribute. */ export declare function getFormMethod(event: SubmitEvent): 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'; /** * Trigger a form submit event with an optional submitter. * If the submitter is not mounted, it will be appended to the form and removed after submission. */ export declare function requestSubmit(form: HTMLFormElement | null | undefined, submitter: Submitter | null): void;