- Docs
- Read the bound form with getters
Read the bound form with getters
Read-only getters that return the bound HTMLFormElement, or null if the binding target was unresolved at construction time.
Read-only getters that return the bound HTMLFormElement, or null if the binding target was unresolved at construction time.
Signatures
interface FormController {
readonly element: HTMLFormElement | null
readonly f: HTMLFormElement | null
readonly options: FormControllerOptions
}
element— the bound form.f— alias ofelement, kept short for fluent setup.options— the resolved options object (defaults merged with user-provided values).
Returns
HTMLFormElement | null. null when the target passed to form() did not resolve to a form.
Examples
Read the bound form
import { form } from '@samline/forms'
const profile = form('profile-form')
if (profile.element) {
profile.element.classList.add('mounted')
}
Use the short alias
import { form } from '@samline/forms'
const profile = form('profile-form')
profile.f?.querySelector('[data-status]')?.setAttribute('data-state', 'ready')
Read the resolved options
import { form } from '@samline/forms'
const profile = form('profile-form', {
autoValidate: false,
attributes: { error: 'is-invalid' },
formats: {
phone: { type: 'phone', field: 'phone', options: { country: 'MX' } },
},
})
profile.options.autoValidate // false (overridden)
profile.options.autoSubmit // false (default)
profile.options.clearErrorsOnSubmit // true (default)
profile.options.attributes.error // 'is-invalid'
profile.options.attributes.filled // 'css-filled' (default)
profile.options.formats.phone // FieldFormatConfig (overridden)
The formats key is the declarative counterpart to format() — see the option reference for the full shape.
Edge cases
- The getter returns
nullwhen the target wasnull,undefined, a non-existent id, or an element that is not anHTMLFormElement. - The reference is the same one the controller uses internally — do not replace the form node, or the controller will keep listening to the original.
Related
form(target, options?)— bind a controller.destroy— tear the controller down.