@hecto/form
v3.0.0
Published
`@hecto/form/view` is an optional adapter. `useForm(options)` creates an owned service; `useFormService(service)` borrows one and releases only its field subscriptions and registrations. Call both inside a View owner. A borrowed idle service is activated
Readme
Native View fields
@hecto/form/view is an optional adapter. useForm(options) creates an owned service;
useFormService(service) borrows one and releases only its field subscriptions and registrations.
Call both inside a View owner. A borrowed idle service is activated by its caller. Server rendering
reads initial state without starting services, registering fields, subscribing or scheduling timers.
import { useForm } from '@hecto/form/view'
const form = useForm({
defaultValues: { name: '', age: 0, tags: [] as string[] },
onSubmit(values) { save(values) },
})
const name = form.field('name', { key: 'profile.name', parse: value => String(value) })
// Native input: spread name.inputProps(), bind value to name.value.
// The form element receives form.formProps().
form.field('age').setValue(42)
form.array('tags').append('native')Fields support typed top-level names and readonly path tuples such as ['people', 0, 'name'].
Value, array item, validation and submit callback types come from the supplied initial/default
values. Native validators are keyed by top-level fields; the neutral service retains explicit
path-based validation. Schema validators currently report issues; they do not transform submitted
values, so this adapter does not claim a separate inferred schema-output value.
Give input-bound fields an explicit stable key and inverse parse function during setup,
before constructing their DOM controls. The adapter adopts captured early browser input into the
same service and emits data-hg-field. value() and field metadata track only that field's
selection. inputProps() requires this explicit adapter; read-only fields need no input options.
Control inversion is explicit: the default kind: 'text' reads a string; kind: 'checked'
emits checked and parses a boolean; kind: 'multiple' emits multiple and an array-valued
value; kind: 'radio' requires optionValue and updates the shared field only for its checked
option. Supply a unique hydration key per radio option. format, when supplied, returns the
matching string, boolean or string-array DOM value. Bind live value/checked properties to
field accessors when constructing controls imperatively; HGX reactive spreads can call
field.inputProps(). Types alone never choose a control mode.
Separate bindings to one field share a reference-counted registration. Disposal cancels pending
activation and allows remount. connectForm now caches its live fields and exposes field.dispose()
and form.dispose() for non-View ownership; inactive fields wait on the service lifecycle without
retry timers, and termination releases their waiters.
