Skip to content

Group

Group<T> holds a named set of fields (or nested groups/lists) and exposes their combined value as a plain object. It participates in the same action and validation system as Field.

Creating a group

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

const form = new Group({
  firstName: Field.create({ value: 'John' }),
  lastName:  Field.create({ value: 'Doe' }),
  age:       Field.create<number>({ value: 30 }),
});

new Group(fields, params?)

ParameterTypeDefaultDescription
fieldsRecord<string, IField>requiredMap of field name → field/group/list instance
params.valueobject | nullnullInitial values applied to matching fields
params.originalValueobject | nullsame as valueBaseline for isChanged
params.enabledbooleantruePropagated to all child fields
params.visibilityDisplayModeDisplayMode.FULLRendering visibility hint
params.validatorsIFieldAction[][]Group-level validators
params.actionsIFieldAction[][]Group-level actions

Group.createFromFormData(data)

Creates a Group from a plain Record<string, any> by wrapping each value in a Field. Useful when building a form from raw API data.

typescript
const form = Group.createFromFormData({ name: 'Alice', score: 42 });

Properties

PropertyTypeWritableDescription
fieldsTnoThe typed map of child fields
valueFieldsToValues<T> | nullyesSerialized object of enabled field values; null if all fields are disabled
reactiveValueComputedRef<...>noVue computed ref of value
originalValueobject | nullnoValue at creation time
isChangedbooleannotrue when value differs from originalValue
validbooleannotrue when the group itself and all child fields are valid
validatingbooleannotrue while any child has a pending async validator
errorsValidationError[]noGroup-level validation errors
enabledbooleanyesSetting this does not cascade to children; use child fields directly
visibilityDisplayModeyesRendering visibility hint
touchedbooleanyestrue when any child field has been touched; setting propagates to all children
fullValueRecord<string, any>noLike value but includes disabled fields

Serialization rule

Group.value serializes only enabled fields. A disabled field is completely excluded from the output object. An exception applies to a disabled nested Group: it is still included if it is non-empty (i.e. it has at least one enabled child).

Methods

field(fieldName): T[K] | null

Type-safe accessor for a single child field. Returns null if the key does not exist.

typescript
const first = form.field('firstName'); // typed as Field<string>

registerAction(action): this

Registers an action on the group itself (not on children). Returns this.

validate(revalidate?): void

Validates the group. Pass revalidate: true to cascade validation to all children.

notifyValueChanged()

Called internally when a child value changes. You rarely need to call this directly.

clone(overrides?): Group<T>

Returns a new Group with cloned children and actions. overrides can replace value, originalValue, enabled, or visibility.


See also: Basic Form example, Conditional statements example

Released under the MIT License.