import * as types from '@babel/types'; import { UIDLElement, UIDLFormDefinition } from '@teleporthq/teleport-types'; export declare const FIELD_ERROR_MESSAGE_ATTR = "data-error-message"; /** Whether the form's own captcha check is on; absent means on. */ export declare const isCaptchaEnabled: (formDefinition: UIDLFormDefinition | undefined) => boolean; /** Whether any field inside the form carries its own validation message. */ export declare const formHasFieldErrorMessages: (formElement: UIDLElement) => boolean; /** * `useEffect` that shows a field's `data-error-message` instead of the * browser's own wording when the field fails validation, and clears it as soon * as the value changes so the next check starts fresh. * * Listeners sit on `document` in the capture phase (`invalid` does not * bubble), scoped to this form by its selector, so a form that renders later — * inside a popup, behind a condition — and every copy on the page are covered. * A radio group carries its message on one button, but the browser may report * any button of the group, so the message is looked up across the group; a * change clears it on every button of the group. Only messages this effect set * are cleared (`applied`), never another script's custom validity. * * const applied = new WeakSet() * const showFieldErrorMessage = (event) => { * const field = event.target * const form = field.closest ? field.closest(formSelector) : null * if (!form) return * const name = field.getAttribute('name') * const carrier = field.hasAttribute('data-error-message') * ? field * : Array.from(form.querySelectorAll('[data-error-message]')).find( * (element) => name && element.getAttribute('name') === name) * const message = carrier ? carrier.getAttribute('data-error-message') : null * if (message) { field.setCustomValidity(message); applied.add(field) } * } * const clearFieldErrorMessage = (event) => { * const field = event.target * const form = field.closest ? field.closest(formSelector) : null * if (!form) return * const name = field.getAttribute('name') * Array.from(form.querySelectorAll('[name]')).concat(field).forEach((element) => { * if ((element === field || (name && element.getAttribute('name') === name)) && * applied.has(element)) { * element.setCustomValidity('') * applied.delete(element) * } * }) * } */ export declare const buildFieldErrorMessagesEffect: (formId: string) => types.ExpressionStatement; //# sourceMappingURL=field-error-messages.d.ts.map