/** * Constraint validation for form-associated ty components. * * Components report their own state (e.g. valueMissing) through set(); users * add a custom error through setCustomValidity(). Both are kept separately and * merged into ElementInternals, so a component re-validating on the next * keystroke doesn't wipe the user's custom error (same as native inputs). * * reportValidity() uses the component's own `error` display when it has one * (ty-input, ty-textarea, ty-radio-group, ty-file-upload) instead of the * browser's bubble, and clears that message again once the field is valid. * Whenever the browser fires `invalid` on such a field — a submit attempt, * form.reportValidity(), or checkValidity() on the field or its form — the * message goes into that error line (no bubble), so a plain
needs no * JS. For a check that shows nothing, read `field.validity.valid` or * `form.matches(':invalid')`. A submit (a submitter click, Enter in a * single-line field, form.requestSubmit()) and form.reportValidity() also * move focus to the first failing field — the first in form order, like a * native form, also when a later field shows a bubble. checkValidity() never * does. For the script-run calls, a form holding a Ty field with an error * line gets own requestSubmit / reportValidity wrappers (the prototype and * other forms are left alone); they come off when the last such field leaves. * An `error` the author set is never overwritten or removed; * form.reset() clears every message the controller wrote. */ /** * Run `fn` as a submit attempt: `invalid` events during it move focus to the * first failing field. ty-button runs its form.requestSubmit() in this. */ export declare function asSubmitAttempt(fn: () => T): T; export declare class ValidityController { private host; private internals; private own; private custom; /** The message this controller last wrote into `error`. */ private written; /** The anchor last handed to setValidity(). */ private anchor?; /** * Anchors a validation bubble was shown on, the last two. WebKit keeps a * pointer to that anchor without keeping it alive: once a re-render drops * it (ty-calendar rebuilds its grid) and it is garbage-collected, the next * submit crashes the page. Held until two later bubbles replaced it. */ private shown; /** The form whose requestSubmit / reportValidity this field keeps wrapped. */ private form; constructor(host: HTMLElement, internals: ElementInternals); /** * The host connected, disconnected or changed form: keep its form's * requestSubmit / reportValidity wrapped while it (or another Ty field with * an error line) is in it. Only such a field needs it: a native control or * a bubble field is focused by the browser itself. */ track(): void; /** * Show the current message, if any, in the error display (on blur after an * edit). During a pointer interaction it waits until after the click. */ reveal(): void; /** * `error` still holds what this controller wrote (a reportValidity(), a * submit, a blur reveal), so it's ours to update and clear. Once the author * sets their own message, it's theirs. */ private get errorFromReport(); private writeError; /** Into `error`, unless the author's own message is there. */ private showError; /** * form.reset(): drop the message this controller showed and any blur * reveal still waiting, so the field looks untouched again. An `error` the * author set stays. */ reset(): void; /** The component's own validity (replaces the previous one). */ set(flags: ValidityStateFlags, message?: string, anchor?: HTMLElement): void; setCustom(message: string): void; report(): boolean; private sync; } type ProbeTag = 'input' | 'textarea' | 'select'; /** * The browser's own (localized) message for a rule: a detached native control * gets the same attributes and value and reports what it would say. `true` * sets a boolean attribute; '', false and null leave the attribute off. One * probe per tag, never in the document, stripped of every attribute before * each use. Works for required and min/max; length rules only report after a * user edit, so a probe can't word them (see lengthValidity()). */ export declare function nativeMessage(tag: ProbeTag, attrs: Record, value?: string): string; /** * nativeMessage() plus the probe's own flags, for rules whose attribute the * browser parses (min/max: ' 5 ' or '0x10' is no rule at all), so the flag * and its message can't disagree. Read `validity` right away: the probe is * reused by the next call. */ export declare function nativeValidity(tag: ProbeTag, attrs: Record, value?: string): { validity: ValidityState; message: string; }; /** Non-negative integer limit from an attribute string, or null when unset/invalid. */ export declare function toLimit(v: unknown): number | null; /** * minlength / maxlength for a text field (ty-input, ty-textarea): the failing * flags with their messages. `control` is the inner native control carrying * `minlength`; it only flags (and words, localized) a value the user typed, * so its message is used then. Otherwise Ty's wording, and the author's * too-short / too-long message always wins. Placeholders: {minlength} * {maxlength} {length}. */ export declare function lengthValidity(value: string, rules: { minlength: unknown; maxlength: unknown; tooShortMessage: string; tooLongMessage: string; }, control?: HTMLInputElement | HTMLTextAreaElement | null): { tooShort?: string; tooLong?: string; }; export {};