import { LitElement } from "lit"; export type SkyFormMode = "client" | "server"; export type SkyFormMethod = "get" | "post"; export type SkyFormEnctype = "application/x-www-form-urlencoded" | "multipart/form-data" | "text/plain"; export type SkyFormAutocomplete = "on" | "off"; export type SkyFormValues = Record; export type SkyFormChangeDetail = { values: SkyFormValues; formData: FormData; success: boolean; }; export type SkyFormValidationErrorsDetail = { errors: string[]; }; export type SkyFormSubmitDetail = { values: SkyFormValues; formData: FormData; success: boolean; }; export type SkyFormFormDataFallbackDetail = { formData: FormData; }; /** * @element sky-form * * @summary Form wrapper with unified validation, error aggregation, and client/server submit flows. * * @status stable * @since 1.0.0 * * @documentation https://sky-ui.com/components/form * * @slot - Form elements: inputs, buttons, and other form controls. * * @property {boolean} liveValidation - Validates and emits `form-change` on value changes. * @property {boolean} showErrors - Shows validation errors in child controls when available. * @property {boolean} errorBox - Shows consolidated validation messages above the form. * @property {string} errorBoxMessage - Header message shown in the consolidated error box. * @property {SkyFormMode} mode - Submission mode (`client` or `server`). * @property {SkyFormMethod | undefined} method - Native form method in server mode. * @property {string | undefined} action - Native form action in server mode. * @property {string | undefined} target - Native form target in server mode. * @property {SkyFormEnctype | undefined} enctype - Native form encoding type. * @property {SkyFormAutocomplete | undefined} autocomplete - Native form autocomplete behavior. * @property {boolean} noValidate - Disables native HTML constraint UI. * @property {boolean} enterSubmit - Submits on Enter for non-textarea controls. * @property {boolean} resetOnSubmit - Resets form after successful submit. * @property {string | null} csrfToken - Optional CSRF token value for app-level submit handling. * @property {string} preset - Named prop preset from nearest `sky-config-provider`. Default: `""`. * * @fires {CustomEvent} form-change - Fired when form values change in live validation mode. * @fires {CustomEvent} validation-errors - Fired when aggregated validation errors change. * @fires {CustomEvent | FormDataEvent} formdata - Fired before client-mode submit with form data. * @fires {CustomEvent} form-submit - Fired after successful client-mode submit handling. * * @method checkValidity Returns native form validity without UI reporting. * @method reportValidity Returns native form validity and reports native UI messages. * @method requestSubmit Requests submission using optional submitter. * @method reset Resets native form and values. * @method resetForm Alias for `reset`. * @method submit Submits form using mode-specific client/server flow. * * @csspart error-box - Container for the consolidated error messages. * @csspart error-list - List element containing validation errors. * * @Behavior * - Provides seamless integration of custom form controls with native HTML form behavior * - Supports both client-side AJAX submissions and traditional server-side submissions * - Automatic validation aggregation from both native and custom form controls * - Light DOM rendering for proper browser form association * * The component automatically associates form controls (including custom elements) with the native form * using the `form` attribute, ensuring proper browser validation and FormData collection. * * - **Live Validation**: Validates on every input change (when liveValidation=true) * - **Submit Validation**: Validates only on form submission * - **Mixed Validation**: Combines both native HTML5 validation and custom component validation * * - **Client Mode**: Prevents page refresh, emits formdata/form-submit events for JavaScript handling * - **Server Mode**: Allows traditional form submission with page navigation/refresh * * @example * ```html * * * * Sign In * * ``` * ```vue * * ``` * ```jsx * export default function Demo() { * return ( * * * * Sign In * * ); * } * ``` */ export declare class SkyForm extends LitElement { /** * When true, validates form on every value change. * @public */ liveValidation: boolean; /** * Controls whether validation errors are displayed. * @public */ showErrors: boolean; /** * When true, displays a consolidated error box with all validation errors. * @public */ errorBox: boolean; /** * Custom message displayed in the error box header. * @public */ errorBoxMessage: string; /** * Submission mode: 'client' prevents page refresh, 'server' allows native form submission. * @public */ mode: SkyFormMode; /** * HTTP method for form submission (when mode='server'). * @public */ method?: SkyFormMethod; /** * URL for form submission (when mode='server'). * @public */ action?: string; /** * Target window/frame for form submission. * @public */ target?: string; /** * Form encoding type. * @public */ enctype?: SkyFormEnctype; /** * HTML autocomplete attribute. * @public */ autocomplete?: SkyFormAutocomplete; /** * When true, disables native HTML5 validation. * @public */ noValidate: boolean; /** * When true, pressing Enter in any input submits the form (except textarea). * @public */ enterSubmit: boolean; /** * When true, resets the form after successful submission. * @public */ resetOnSubmit: boolean; /** * CSRF token for form submission protection. * @public */ csrfToken: string | null; /** * Array of current validation error messages. * @private */ private validationErrors; /** * Indicates whether the last form submission was successful. * @private */ private submitSuccess; /** * Indicates whether validation is currently active (errors shown). * @private */ private validationActive; /** Reference to the native form element. */ private _formEl; private _mo?; private _syncQueued; private _handlingSubmit; private _handlingInvalid; /** MUST be light DOM for button[form="..."] + native id lookup */ /** Named prop preset from nearest `sky-config-provider`. */ preset: string; private _presets; protected createRenderRoot(): this; /** * Returns the native HTML form element. * @public */ get formElement(): HTMLFormElement; connectedCallback(): void; disconnectedCallback(): void; private _queueSync; private _onEnterKey; /** * Make `document.getElementById(hostId)` return the native form. * Copies host id => native form id and removes id from host to avoid duplicate ids. */ private _moveHostIdToNativeForm; /** * Slotted controls remain in the light DOM under ``, not under the inner `
`. * `_assignFormOwnerToChildren` needs a stable `id` on that `` to set `form="…"` on * associated controls. When the host has no `id`, generate one so association still works. */ private _ensureNativeFormHasId; private _handleValueChanged; /** * Whether the form passes constraint validation, without calling `form.checkValidity()`. * `HTMLFormElement.checkValidity()` dispatches `invalid` on each invalid control; during * liveValidation that runs on every keystroke and our capture listener would focus the first * invalid field, stealing focus from the control the user is editing. */ private _formValidQuiet; private _emitFormChange; /** * Assigns form ownership to elements not inside the native element. * Ensures browser association for native submit + validation + FormData. */ private _assignFormOwnerToChildren; private _getSkyInputs; private _emitValidationErrors; private _onFormDataCapture; private _onInvalidCapture; private _refreshAggregates; private _focusFirstInvalid; private _focusElement; private _syncNow; private _onHostSubmitCapture; private _formDataToJSON; /** Activates validation mode and refreshes error aggregates. */ private _activateValidation; /** * Checks form validity without displaying validation messages. * @returns {boolean} True if the form is valid, false otherwise. * @public */ checkValidity(): boolean; /** * Checks form validity and displays validation messages. * @returns {boolean} True if the form is valid, false otherwise. * @public */ reportValidity(): boolean; /** * Requests form submission (compatible with native requestSubmit). * @param {HTMLElement} submitter - Optional submitter element. * @public */ requestSubmit(submitter?: HTMLElement): void; /** * Resets the form to its initial state. * @public */ reset(): void; /** * Resets the form to its initial state (alias for reset()). * @public */ resetForm(): void; /** * Manually submits the form, respecting the current mode setting. * In client mode, triggers the client-side submission flow. * In server mode, performs native form submission. * @public */ submit(): void; render(): import("lit-html").TemplateResult<1>; }