Skip to content

Field

Field<T> represents a single typed form value. The constructor is private — use Field.create().

Creating a field

typescript
import { Field } from '@dynamicforms/vue-forms';

const name = Field.create({ value: 'John' });
const age  = Field.create<number>({ value: 30 });

Field.create<T>(params?)

ParameterTypeDefaultDescription
params.valueTundefinedInitial value
params.originalValueTsame as valueBaseline for isChanged
params.enabledbooleantrueWhether the field accepts input and serializes
params.visibilityDisplayModeDisplayMode.FULLRendering visibility hint
params.validatorsIFieldAction[][]Validator actions (run eagerly on creation)
params.actionsIFieldAction[][]Additional actions to register

Returns a reactive Field<T> instance.

Properties

PropertyTypeWritableDescription
valueTyesCurrent value. Setting it on a disabled field is a no-op.
reactiveValueComputedRef<T>noVue computed ref of value — use in templates instead of value when you need reactivity outside of direct binding
originalValueTnoValue as provided at creation
isChangedbooleannotrue when value differs from originalValue (deep equality)
enabledbooleanyesWhen false, the field ignores value changes and is excluded from Group.value
visibilityDisplayModeyesRendering visibility hint — does not affect serialization
validbooleannotrue when errors is empty
validatingbooleannotrue while an async validator is pending
errorsValidationError[]noCurrent validation errors
touchedbooleanyesWhether the user has interacted with the field
parentGroup | undefinednoParent group when the field is part of a Group
fieldNamestring | undefinednoKey name within the parent Group
fullValueTnoIdentical to value on a plain Field

Methods

registerAction(action): this

Registers an action (validator or event handler). Returns this for chaining.

typescript
field.registerAction(new ValueChangedAction((field, supr, newValue, oldValue) => {
  console.log('changed to', newValue);
  return supr(field, newValue, oldValue);
}));

triggerAction(actionClass, ...params): any

Manually fires a specific action class on this field.

validate(revalidate?): void

Recalculates valid based on errors. Pass revalidate: true to re-trigger all eager validators from scratch.

clearValidators(): void

Removes all registered validators and clears errors.

clone(overrides?): Field<T>

Returns a new reactive field with the same registered actions. overrides can replace value, originalValue, enabled, or visibility.


See also: Basic Form example, Validators example

Released under the MIT License.