Skip to content

Form.withFields

github-actions[bot] edited this page Dec 3, 2024 · 3 revisions
API / Form<TValidationError> / withFields method

Adds the provided fields to the form, returns an observable collection containing them.

Any changes made to the returned collection is reflected in the form as well, added fields are added, removed fields are removed, sorting or moving fields around are moved in the form as well.

protected withFields(
  ...fields: readonly FormField<any, TValidationError>[]
): IObservableCollection<FormField<any, TValidationError>>

Source reference: src/forms/Form.ts:704.

Parameters

Returns: IObservableCollection<FormField<any, TValidationError>>

Returns a collection containing the provided fields. The form reacts to changes made in the returned collection always keeping in sync.

Guidance: Defining a Form

This method adds the provided fields to the form, a necessary step to watch the form fields for changes as well as their validity. The Form.isValid and Form.isInvalid properties are dependent on the fields.

class MyForm extends Form {
  public constructor() {
    super();

    this.withFields(
      this.name = new FormField({
        name: 'name',
        initialValue: ''
      })
    );
  }

  public readonly name: FormField<string>;
}

See also

Clone this wiki locally