FormRegistry
The FormRegistry manages all form controllers. Access via the exported formRegistry singleton.
import { formRegistry } from 'formlayer';Single-form apps
Section titled “Single-form apps”For one form, skip the registry:
import { createFormController, registerDefaultValidators } from 'formlayer';
registerDefaultValidators();const form = createFormController(document.getElementById('contact')!, submitFn);Global validators and field types
Section titled “Global validators and field types”Register globally via module-level APIs (not on the registry):
import { registerValidator, registerFieldType } from 'formlayer';
registerValidator({ type: 'MyValidator', validate(value, options) { ... } });registerFieldType('slider', () => import('./fields/slider'));Methods
Section titled “Methods”init(options)
Section titled “init(options)”Discovers and registers all matching forms.
formRegistry.init({ submitFn: FormSubmitFunction, root?: ParentNode, // default: document formSelector?: string, // default: 'form[id]' controllerOptions?: FormControllerOptions,}): voidregister(formEl, submitFn, controllerOptions?)
Section titled “register(formEl, submitFn, controllerOptions?)”Registers a single form element. Returns the form controller API. No-ops if already registered.
const api: FormControllerApi = formRegistry.register(formEl, submitFn);unregister(formId)
Section titled “unregister(formId)”Destroys the controller and removes the form from the registry.
formRegistry.unregister('my-form');get(formId)
Section titled “get(formId)”Returns the FormControllerApi for a registered form, or undefined.
const form = formRegistry.get('contact');getAll()
Section titled “getAll()”Returns a Map<string, FormControllerApi> of all registered forms.
on(event, handler) / off(event, handler)
Section titled “on(event, handler) / off(event, handler)”Subscribe to registry-level events.
formRegistry.on('form:registered', ({ formId }) => { ... });formRegistry.on('form:unregistered', ({ formId }) => { ... });registerFormPlugin(factory)
Section titled “registerFormPlugin(factory)”Registers a form-level plugin factory. Applied to all forms registered after this call.
formRegistry.registerFormPlugin(() => import('./plugins/analytics'));Global Access
Section titled “Global Access”The registry is also available globally as window.__FormsModule (browser environments only).