# Forms

Forms are components designed to create and structure input masks, consisting of multiple input controls. They are configurable to fit various use cases and layouts.

## Usage

A form is a set of related input controls that allow users to provide information.

![Form](<../images/form.png>)

### Best practices

- Keep it short. Remove fields that collect redundant, untimely, or unnecessary information.
- Ask for information in a logical sequence.
- Visually group related fields.
- Match fields to the type and size of the expected input.
- When possible, use smart defaults and typeahead behavior.
- Don’t rely on placeholders; include a short and meaningful label.
- Distinguish optional and required fields. Required fields can be indicated using an asterisk.
- Make action buttons task-specific

## Design

### Elements

![Form - Elements](<../images/form-elements.png>)

Forms can be comprised of some or all of the following elements:

1. **Title:** A brief headline that indicates the form's purpose or the information it collects.
2. **Form body:** Enable users to insert free or specific form text (e.g: [text inputs](<https://element.siemens.io/components/forms-inputs/input/>), [select](<https://element.siemens.io/components/forms-inputs/select/>), [checkboxes](<https://element.siemens.io/components/forms-inputs/checkbox/>), [radio buttons](<https://element.siemens.io/components/forms-inputs/radio/>), and more).
3. **Actions:** Allow users to submit or quit a form.

### States

The status of the form directly corresponds to the status of each of its individual fields.

![Form - Status](<../images/form-status.png>)

### Labels

Labels can be placed on top of fields or to the left (in RTL languages). All labels in a single form should use the same placement style. **Prefer top placement of labels**, since it provides a consistent left edge alignment, improving scannability.

### Validation

Always display error states within the form and prioritize the use of inline validation.

- Inline validation: This validates user data while they fill out the form, being triggered immediately after a field loses focus.
- Post-submission validation: This assesses the entire form's data only after the user has submitted it, providing feedback through inline notifications.

![Form - Validation](<../images/form-validation.png>)

## Code

User input is one of the essential pillars of many applications. Read [Forms in Angular](<https://angular.dev/guide/forms>) as basis for working with forms.

The following are important yet repetitive tasks for every form control (e.g. input, textarea, checkbox) of a form:

- For accessibility, linking a `<label>` to its input using `id`/`for` attributes or aria attributes.
- the label must be correctly aligned for different types, e.g. text, checkbox, ...
- Display meaningful validation error messages on input to guide and support the user.
- Group related form fields to a fieldset. For example, multiple radio checkbox inputs belong to one input and have one label.

Element provides components to shift repetitive and common tasks from the application developers to the framework.

We support all Angular form implementations. Choose the Element component depending on the Angular form feature you use:

- Signal forms (`formField`) --\> use `si-form-field`
- Reactive forms (`formControl` / `formControlName`) --\> use `si-form-item`
- Template driven forms (`ngModel`) --\> `si-form-item`

Both `si-form-field` and `si-form-item` have a very similar interface and interact the same way with other Element components. In the following only `si-form-field` is shown, but `si-form-item` is always usuable the same way.

The `si-form-field` component is a wrapper around a form control element that renders the associated label.

```
<si-form-field label="My form field">
  <input [formField]="form.field" class="form-control" />
</si-form-field>
```

The `si-form-field` component adds and links a label to the control in compliance to [WCAG v2.2](<https://www.w3.org/TR/WCAG22/>), so that screen readers are able to guide users through the form.

Native controls like `<input>` and Element controls like `si-select` are only recognized by the `si-form-field` if they are an Angular form field, meaning that they have `[formField]` attached (for `si-form-item`: `[formControl]`, `[formControlName]` or `[ngModel]`).

### Form feedback

Element form controls should provide user feedback on user input. [Angular Forms](<https://angular.dev/guide/forms/signals/validation>) handle valid and invalid form states automatically. In addition, Element supports setting form control states and feedback messages explicitly in the template:

```
<si-form-field label="Warning item">
  <input class="form-control is-warning" />
  <span class="warning-feedback">Attention, this is a Warning!</span>
</si-form-field>
```

These states are available:

- valid --\> `is-valid`
- warning --\> `is-warning`
- error --\> `is-error`

For warning and error states, a respective icon is automatically added. Starting with Element v46, the feedback icon **must not** be added manually.

### Error messages

`si-form-field` is capable of showing errors from Angular's validation mechanism automatically. Element has a built-in resolution of standard errors like `required`. On top of that, Element supports configuring the resolution mechanism. This enables applications to adjust existing messages and add new ones for custom validators.

#### Global error resolution

For a standalone app:

```
import { ApplicationConfig } from '@angular/core';
import { provideFormValidationErrorMapper } from '@siemens/element-ng/form';

export const appConfig: ApplicationConfig = {
  providers: [
    provideFormValidationErrorMapper({
      maxlength: 'MY.CUSTOM.ERROR.MESSAGE.KEY', // when using ngx-translate one has access to the validation result as parameters (requiredLength and actualLength in this case)
      minlength: ({ requiredLength }) =>
        `This field must be at least ${requriredLength} characters long`,
      myCustomError: ({ myCustomErrorResult }) => `My custom error message: ${myCustomErrorResult}`
    })
  ]
};
```

or for a module base app:

```
import {SiFormModule} from '@siemens/element-ng/form';

@NgModule({
  imports: [
    SiFormModule.withConfiguration({
      validationErrorMapper: {
        maxlength: 'MY.CUSTOM.ERROR.MESSAGE.KEY', // when using ngx-translate one has access to the validation result as parameters (requiredLength and actualLength in this case)
        minlength: ({ requiredLength }) => `This field must be at least ${requriredLength} characters long`,
        myCustomError: ({ myCustomErrorResult }) => `My custom error message: ${myCustomErrorResult}`,
      },
    })
  ],
})
```

#### Local error resolution

For the `si-form-field` use the message property the form schema:

```
this.form = form(this.formModel, schemaPath => {
  required(schemaPath.field, { message: 'MY.REQUIRED_ERROR' });
});
```

For the `si-form-item` use the `formErrorMapper` input:

```
<si-form-item label="Required input" [formErrorMapper]="{required: 'MY.REQUIRED_ERROR'}">
  ...
</si-form-item>
```

### Required detection

`si-form-field` automatically detects whether a form control is required. It does this by checking if Angular's required validator is attached.

To have this check working, make sure that only the standard validators of Angular are used.

### Form fieldset

Use a `si-form-fieldset` to group multiple related `si-form-field`. This is often required for radio inputs, but works for every other type as well.

```
<si-form-fieldset label="Radion options">
  <si-form-field label="Radio option A">
    <input type="radio" class="form-check-input" />
  </si-form-field>
  <si-form-field label="Radio option B">
    <input type="radio" class="form-check-input" />
  </si-form-field>
</si-form-fieldset>
```

### Context help

To provide contextual help within form fields, use the `SiHelpButtonComponent`. Add the `si-help-button` directive to a button placed inside the form field. This allows you to display additional information or guidance related to the input field.

```
<si-form-field label="Input label">
  <button
    si-help-button
    type="button"
    siHelpTitle="Help for input"
    siHelpContent="The context help description"
  >
  </button>
  <input class="form-control" />
</si-form-field>
```

### Custom controls

`si-form-field` provides an API for being linked to custom controls implemented by an application. Custom controls must implement the `SiFormItemControl` interface and provide themselves as `SI_FORM_ITEM_CONTROL`:

```
import { SI_FORM_ITEM_CONTROL, SiFormItemControl } from '@siemens/element-ng/form';
import { Component } from '@angular/core';

@Component({
  providers: [{ provide: SI_FORM_ITEM_CONTROL, useExisting: CustomControlComponent }]
})
export class CustomControlComponent implements SiFormItemControl {
  // Provide an automatically generated ID.
  // If your component is only a wrapper around either an input, textarea or select,
  // assign this ID to that element. Otherwise assign it to the host element.
  private static idCounter = 0;
  readonly id = `__app-custom-control-${CustomControlComponent.idCounter++}`;

  // Set this only if the custom-control is NOT an input, textarea or select.
  // It is required as the [for] attribute of an label only works for native inputs.
  readonly labelledby = `${this.id}-label`;

  // Set to true if, the control should be rendered like a checkbox. This only affects the positioning of the label.
  // If false, this should be omitted.
  readonly isFormCheck = false;
}
```

For HTML Elements that are marked as `form-control` (--\> input like appearance), icons are automatically included. If the form-control contains custom icons at the end, like the dropdown arrow for select, wrap them in a `form-control-actions` element.

The `form-control-actions` element handles layout (height, vertical centering, spacing) and renders the validation feedback icon on its leading edge. It can be used in two ways.

When `form-control-actions` is a sibling of a `form-control`, wrap both elements in the same positioned container, for example one with `position-relative`.

Do not add `form-control-actions` to a component that already renders it internally. This applies to `si-calendar-button`, `si-password-toggle`, `si-date-range`, `si-number-input`, `si-select`, and `si-select-combobox`. `si-calendar-button` and `si-password-toggle` also provide the positioned container required by the sibling pattern.

1. **Inside a custom composite `form-control`**: The wrapper owns the trailing space, so no `--si-action-icon-offset` is needed. The custom control is responsible for its internal layout.

```
<div class="form-control">
  <input />
  <div class="form-control-actions">
    <i class="my-action-icon element-arrow-down icon"></i>
  </div>
</div>
```

1. **As a sibling of the input**: The `form-control-actions` element is pinned to the top-right edge of the input. Set `--si-action-icon-offset` on the input to reserve space for the actions so the input's content does not overlap them. Wrap both elements in a positioned container.

```
<div class="position-relative">
  <input class="form-control" style="--si-action-icon-offset: 1.5rem" />
  <div class="form-control-actions">
    <button type="button" class="my-action-button"></button>
  </div>
</div>
```

### Column layout

Forms can switch to a column layout where labels are displayed next to the input. Apply the respective classes directly on the `form` to enable the column layout.

`responsive-form-col-layout` switches to the column mode only above `48ch`, `form-col-layout` switches screensize independent to the column layout.

```
<form class="responsive-form-col-layout"> ... </form>
```

To customize the breakpoint, use the `responsive-form-col-layout` mixin within your component that holds the form:

```
@use '@siemens/element-theme/src/styles/bootstrap/mixins/form-layout';

:host {
  // Above 400px the column layout is used
  @include form-layout.responsive-form-col-layout(400px);
}
```

### Example

#### Example

##### Signal Form

Component:

```typescript
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { Component, signal } from '@angular/core';
import {
  disabled as disabledField,
  form,
  FormField,
  FormRoot,
  minLength,
  pattern,
  readonly as readonlyField,
  required,
  validate
} from '@angular/forms/signals';
import { SiCardComponent } from '@siemens/element-ng/card';
import {
  DateRange,
  SiCalendarButtonComponent,
  SiDatepickerDirective,
  SiDateRangeComponent,
  SiTimepickerComponent
} from '@siemens/element-ng/datepicker';
import {
  provideSiFormFieldConfig,
  SiFormFieldComponent,
  SiFormFieldsetComponent
} from '@siemens/element-ng/form';
import { SiPhoneNumberInputComponent } from '@siemens/element-ng/phone-number';

export type Role = 'ENGINEER' | 'INSTALLER';
import { SiHelpButtonComponent } from '@siemens/element-ng/help-button';
import { SiNumberInputComponent } from '@siemens/element-ng/number-input';
import { SelectOption, SiSelectModule } from '@siemens/element-ng/select';

import { SiFormDebugComponent } from './si-form-debug';

export interface TravelRequest {
  name: string;
  description: string;
  phoneNumber: string;
  birthday: Date | string;
  travelDate: DateRange;
  arrival: Date | null;
  departure: Date | null;
  serviceClass: string;
  role: Role | '';
  fellowPassengers: number;
  termsAccepted: boolean;
  privacyDeclined: boolean;
}

const emptyRequest: TravelRequest = {
  name: '',
  description: '',
  phoneNumber: '',
  birthday: '',
  travelDate: { start: undefined, end: undefined },
  arrival: null,
  departure: null,
  serviceClass: 'first',
  role: '',
  fellowPassengers: 0,
  termsAccepted: false,
  privacyDeclined: false
};

@Component({
  selector: 'app-sample',
  imports: [
    FormField,
    FormRoot,
    SiCardComponent,
    SiCalendarButtonComponent,
    SiDatepickerDirective,
    SiDateRangeComponent,
    SiFormDebugComponent,
    SiFormFieldComponent,
    SiFormFieldsetComponent,
    SiHelpButtonComponent,
    SiNumberInputComponent,
    SiPhoneNumberInputComponent,
    SiSelectModule,
    SiTimepickerComponent
  ],
  templateUrl: './si-signal-form.html',
  providers: [provideSiFormFieldConfig()],
  host: { class: 'p-5' }
})
export class SampleComponent {
  protected readonly optionsList: SelectOption<string>[] = [
    {
      type: 'option',
      value: 'first',
      icon: 'element-face-happy',
      iconColor: 'status-success',
      label: 'First class'
    },
    {
      type: 'option',
      value: 'business',
      icon: 'element-face-neutral',
      iconColor: 'status-warning',
      label: 'Business'
    },
    {
      type: 'option',
      value: 'economy',
      icon: 'element-face-unhappy',
      iconColor: 'status-danger',
      label: 'Economy'
    }
  ];

  protected readonly model = signal<TravelRequest>({ ...emptyRequest });

  protected readonly submitted = signal<TravelRequest | undefined>(undefined);
  protected readonly debugState = signal({ disabled: false, readonly: false });

  protected readonly form = form(
    this.model,
    path => {
      disabledField(path, { when: () => this.debugState().disabled });
      readonlyField(path, { when: () => this.debugState().readonly });
      disabledField(path.role, { when: () => this.debugState().readonly });
      disabledField(path.termsAccepted, { when: () => this.debugState().readonly });
      disabledField(path.privacyDeclined, { when: () => this.debugState().readonly });
      required(path.name, { message: 'Required' });
      minLength(path.name, 3, { message: 'Min. 3 characters' });
      pattern(path.name, /^[A-Z].*/, {
        message: 'Name must start with an uppercase letter.'
      });
      required(path.birthday, { message: 'Required' });
      validate(path.birthday, ({ value }) => {
        const valueAsDate = value();
        if (!valueAsDate) {
          return undefined;
        }

        const birthday = new Date(valueAsDate);
        if (isNaN(birthday.getTime())) {
          return undefined;
        }

        const age = Date.now() - birthday.getTime();
        return age >= 18 * 31556952000
          ? undefined
          : { kind: 'notEighteen', message: 'You must be at least 18 years old.' };
      });
      required(path.travelDate, { message: 'Travel date is required.' });
      validate(path.travelDate, ({ value }) => {
        const { start, end } = value();
        return !start || !end
          ? { kind: 'required', message: 'Travel date is required.' }
          : undefined;
      });
      required(path.arrival, { message: 'Required' });
      required(path.departure, { message: 'Required' });
      validate(path.departure, ctx => {
        const arrival = ctx.valueOf(path.arrival);
        const departure = ctx.value();
        if (!arrival || !departure) {
          return undefined;
        }

        return departure.getTime() >= arrival.getTime()
          ? undefined
          : { kind: 'departureTime', message: 'The departure time must be after arrival.' };
      });
      validate(path.serviceClass, ({ value }) =>
        value() === 'economy' ? { kind: 'noEconomy', message: 'You deserve better!' } : undefined
      );
      required(path.role, { message: 'Role required' });
      validate(path.fellowPassengers, ({ value }) =>
        value() >= 2 ? undefined : { kind: 'min', message: 'Min. 2' }
      );
      required(path.termsAccepted, {
        message: 'You need to accept all terms before joining.'
      });
      required(path.privacyDeclined, {
        message: 'Required'
      });
    },
    {
      submission: {
        action: async () => {
          this.submitted.set(structuredClone(this.model()));
          return undefined;
        }
      }
    }
  );

  protected cancel(): void {
    const submitted = this.submitted();
    this.form().reset(structuredClone(submitted ?? emptyRequest));
  }
}
```

Template:

```html
<div class="container-fluid">
  <div class="row gy-5">
    <div class="col-12 col-md">
      <si-card heading="Signal Form">
        <div class="card-body" body>
          <form class="responsive-form-col-layout" [formRoot]="form">
            <si-form-fieldset label="Role" inline>
              <si-form-field label="Engineer">
                <input
                  type="radio"
                  class="form-check-input"
                  value="ENGINEER"
                  [formField]="form.role"
                />
              </si-form-field>
              <si-form-field label="Installer">
                <input
                  type="radio"
                  class="form-check-input"
                  value="INSTALLER"
                  [formField]="form.role"
                />
              </si-form-field>
              <button
                si-help-button
                type="button"
                siHelpTitle="More information"
                siHelpContent="A role must be selected."
                >More information about the role</button
              >
            </si-form-fieldset>

            <si-form-field label="Name">
              <input type="text" class="form-control" [formField]="form.name" />
              <button
                si-help-button
                type="button"
                siHelpTitle="More information"
                siHelpContent="Full name must start with an uppercase letter and be at least 3 characters long."
                >More information about the name</button
              >
            </si-form-field>

            <si-form-field label="Description">
              <input type="text" class="form-control" [formField]="form.description" />
            </si-form-field>

            <si-form-field label="Phone number">
              <si-phone-number-input
                class="form-control"
                defaultCountry="CH"
                placeholderForSearch="Search"
                selectCountryAriaLabel="Select country"
                [formField]="form.phoneNumber"
                [supportedCountries]="['AU', 'CH', 'DE', 'FK', 'IN', 'US']"
              />
            </si-form-field>

            <si-form-field label="Day of birth">
              <si-calendar-button class="w-100">
                <input
                  type="text"
                  class="w-100 form-control"
                  autocomplete="off"
                  siDatepicker
                  [formField]="form.birthday"
                />
              </si-calendar-button>
            </si-form-field>

            <si-form-field label="Travel Date">
              <si-date-range class="w-100" [formField]="form.travelDate" />
            </si-form-field>

            <si-form-field label="Arrival">
              <si-timepicker [hideLabels]="true" [formField]="form.arrival" />
            </si-form-field>

            <si-form-field label="Departure">
              <si-timepicker [hideLabels]="true" [formField]="form.departure" />
            </si-form-field>

            <si-form-field label="Class of service">
              <si-select
                class="form-control"
                [options]="optionsList"
                [formField]="form.serviceClass"
              />
            </si-form-field>

            <si-form-field label="Fellow passengers">
              <si-number-input class="form-control" [formField]="form.fellowPassengers" />
            </si-form-field>

            <si-form-fieldset label="Accept terms">
              <si-form-field label="I confirm that I accept all and everything.">
                <input type="checkbox" class="form-check-input" [formField]="form.termsAccepted" />
                <button
                  si-help-button
                  type="button"
                  siHelpTitle="More information"
                  siHelpContent="Acceptance of terms and conditions is required to join."
                  >More information about the terms</button
                >
              </si-form-field>

              <si-form-field label="I confirm that I do not care about my privacy.">
                <input
                  type="checkbox"
                  class="form-check-input"
                  [formField]="form.privacyDeclined"
                />
              </si-form-field>
            </si-form-fieldset>

            <div class="d-flex justify-content-end mt-6">
              <button type="button" class="btn btn-secondary me-6" (click)="cancel()">
                Cancel
              </button>
              <button type="submit" class="btn btn-primary">Save</button>
            </div>
          </form>
        </div>
      </si-card>
    </div>

    <app-form-debug
      [formData]="model()"
      [submitted]="submitted()"
      [validationStatus]="form().valid() ? 'VALID' : 'INVALID'"
      [(state)]="debugState"
    />
  </div>
</div>
```

##### Reactive Form

Component:

```typescript
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { Component, effect, signal } from '@angular/core';
import {
  AbstractControl,
  FormControl,
  FormGroup,
  ReactiveFormsModule,
  ValidationErrors,
  ValidatorFn,
  Validators
} from '@angular/forms';
// eslint-disable-next-line no-restricted-imports
import { TranslatePipe } from '@ngx-translate/core';
import { SiCardComponent } from '@siemens/element-ng/card';
import {
  DateRange,
  SiCalendarButtonComponent,
  SiDatepickerDirective,
  SiDateRangeComponent,
  SiTimepickerComponent
} from '@siemens/element-ng/datepicker';
import { provideFormValidationErrorMapper, SiFormModule } from '@siemens/element-ng/form';
import { SiHelpButtonComponent } from '@siemens/element-ng/help-button';
import { SiNumberInputComponent } from '@siemens/element-ng/number-input';
import { PhoneDetails, SiPhoneNumberInputComponent } from '@siemens/element-ng/phone-number';
import { SelectOption, SiSelectModule } from '@siemens/element-ng/select';

import { SiFormDebugComponent } from './si-form-debug';

export type Role = 'ENGINEER' | 'INSTALLER';

export class Entity {
  id!: number;
  name!: string;
  role!: Role;
  description?: string;
  phoneNumber?: PhoneDetails;
  termsAccepted = false;
  birthday!: Date;
  travelDate!: DateRange;
  arrival?: Date;
  departure?: Date;
  serviceClass!: string;
}

export const is18Years: ValidatorFn = (control: AbstractControl): ValidationErrors | null => {
  if (!control.value || isNaN(control.value.getTime())) {
    return null;
  }
  const date: Date = control.value;
  const now = new Date();
  const eighteen = 18 * 31556952000;
  const diff = now.getTime() - date.getTime();
  return diff >= eighteen ? null : { notEighteen: control.value };
};

export const arrivalDepartureTimeValidator: ValidatorFn = (
  form: AbstractControl
): ValidationErrors | null => {
  const start = form.get('arrival')!;
  const end = form.get('departure')!;

  if (start.value && end.value && end.value.getTime() - start.value.getTime() < 0) {
    end.setErrors({ departureTime: true });
  }

  return null;
};

export const noEconomy: ValidatorFn = control => {
  if (control.value === 'economy') {
    return {
      noEconomy: true
    };
  }
  return null;
};

@Component({
  selector: 'app-sample',
  imports: [
    ReactiveFormsModule,
    SiCalendarButtonComponent,
    SiCardComponent,
    SiDatepickerDirective,
    SiDateRangeComponent,
    SiFormDebugComponent,
    SiFormModule,
    SiHelpButtonComponent,
    SiNumberInputComponent,
    SiPhoneNumberInputComponent,
    SiSelectModule,
    SiTimepickerComponent,
    TranslatePipe
  ],
  templateUrl: './si-reactive-form.html',
  providers: [
    provideFormValidationErrorMapper({
      'name.pattern': 'Name must start with an uppercase letter.',
      'name.required': 'FORM.NAME_REQUIRED',
      'termsAccepted.required': 'FORM.ACCEPT_TERMS_REQUIRED',
      notEighteen: 'You must be at least 18 years old.',
      departureTime: 'FORM.DEPARTURE_AFTER_ARRIVAL',
      'travelDate.endBeforeStart': 'FORM.END_BEFORE_START',
      'travelDate.required': 'FORM.TRAVEL_DATE_REQUIRED',
      noEconomy: 'You deserve better!'
    })
  ],
  host: { class: 'p-5' }
})
export class SampleComponent {
  optionsList: SelectOption<string>[] = [
    {
      type: 'option',
      value: 'first',
      icon: 'element-face-happy',
      iconColor: 'status-success',
      label: 'First class'
    },
    {
      type: 'option',
      value: 'business',
      icon: 'element-face-neutral',
      iconColor: 'status-warning',
      label: 'Business'
    },
    {
      type: 'option',
      value: 'economy',
      icon: 'element-face-unhappy',
      iconColor: 'status-danger',
      label: 'Economy'
    }
  ];

  submitted?: Entity;

  form = new FormGroup(
    {
      name: new FormControl(''),
      role: new FormControl<Role | null>(null, [Validators.required]),
      description: new FormControl(''),
      phoneNumber: new FormControl<PhoneDetails | null>(null),
      birthday: new FormControl<Date | string>('', is18Years),
      travelDate: new FormControl<DateRange | null>(null),
      arrival: new FormControl<Date | null>(null, Validators.required),
      departure: new FormControl<Date | null>(null, Validators.required),
      serviceClass: new FormControl('first', noEconomy),
      fellowPassengers: new FormControl(0, Validators.min(2)),
      termsAccepted: new FormControl<boolean>(false),
      privacyDeclined: new FormControl<boolean>(false)
    },
    [arrivalDepartureTimeValidator]
  );

  readonly debugState = signal({ disabled: false, readonly: false });
  readonly = false;

  constructor() {
    effect(() => {
      const { disabled, readonly } = this.debugState();
      this.readonly = readonly;

      if (disabled) {
        this.form.disable();
      } else {
        this.form.enable();
        if (readonly) {
          this.form.controls.role.disable();
          this.form.controls.privacyDeclined.disable();
          this.form.controls.termsAccepted.disable();
        }
      }
    });
  }

  save(): void {
    if (this.form.invalid) {
      this.form.markAllAsTouched();
      return;
    }
    this.submitted = new Entity();
    Object.assign(this.submitted, this.form.getRawValue());
  }

  cancel(): void {
    this.form.reset(this.submitted);
  }
}
```

Template:

```html
<div class="container-fluid">
  <div class="row gy-5">
    <div class="col">
      <si-card heading="Reactive Form">
        <div class="card-body" body>
          <form class="responsive-form-col-layout" [formGroup]="form" (ngSubmit)="save()">
            <si-form-fieldset label="FORM.ROLE" inline>
              <button
                si-help-button
                type="button"
                siHelpTitle="FORM.INPUT_HELP_TITLE"
                siHelpContent="FORM.INPUT_HELP_DESCRIPTION"
                >{{ 'FORM.ROLE_MORE_INFORMATION' | translate }}</button
              >
              <si-form-item label="FORM.ENGINEER">
                <input
                  type="radio"
                  formControlName="role"
                  value="ENGINEER"
                  id="role-engineer"
                  class="form-check-input"
                />
              </si-form-item>
              <si-form-item label="FORM.INSTALLER">
                <input
                  type="radio"
                  formControlName="role"
                  value="INSTALLER"
                  id="role-installer"
                  class="form-check-input"
                />
              </si-form-item>
            </si-form-fieldset>
            <si-form-item label="FORM.NAME">
              <input
                type="text"
                id="name"
                class="form-control"
                formControlName="name"
                required
                minlength="3"
                pattern="^[A-Z].*"
                [readonly]="readonly"
              />
              <button
                si-help-button
                type="button"
                siHelpTitle="FORM.INPUT_HELP_TITLE"
                siHelpContent="FORM.INPUT_HELP_DESCRIPTION"
                >{{ 'FORM.NAME_MORE_INFORMATION' | translate }}</button
              >
            </si-form-item>
            <si-form-item label="FORM.DESCRIPTION">
              <input
                type="text"
                id="description"
                class="w-100 form-control"
                formControlName="description"
                [readonly]="readonly"
              />
            </si-form-item>
            <si-form-item label="FORM.PHONE_NUMBER">
              <si-phone-number-input
                class="form-control"
                formControlName="phoneNumber"
                defaultCountry="CH"
                placeholderForSearch="FORM.SEARCH"
                selectCountryAriaLabel="FORM.SELECT_COUNTRY"
                [supportedCountries]="['AU', 'CH', 'DE', 'FK', 'IN', 'US']"
                [readonly]="readonly"
              />
            </si-form-item>
            <si-form-item label="FORM.BIRTHDAY">
              <si-calendar-button class="w-100">
                <input
                  type="text"
                  id="birthday"
                  class="w-100 form-control"
                  autocomplete="off"
                  formControlName="birthday"
                  siDatepicker
                  required
                  [readonly]="readonly"
                />
              </si-calendar-button>
            </si-form-item>
            <si-form-item label="FORM.TRAVEL_DATE">
              <si-date-range
                id="travelDate"
                required
                formControlName="travelDate"
                [readonly]="readonly"
              />
            </si-form-item>
            <si-form-item label="FORM.ARRIVAL">
              <si-timepicker
                id="arrival"
                formControlName="arrival"
                required
                [hideLabels]="true"
                [readonly]="readonly"
              />
            </si-form-item>
            <si-form-item label="FORM.DEPARTURE">
              <si-timepicker
                id="departure"
                formControlName="departure"
                required
                [hideLabels]="true"
                [readonly]="readonly"
              />
            </si-form-item>
            <si-form-item label="FORM.CLASS">
              <si-select
                class="form-control"
                formControlName="serviceClass"
                id="form-class-label"
                [options]="optionsList"
                [readonly]="readonly"
              />
            </si-form-item>
            <si-form-item label="FORM.FELLOW_PASSENGERS">
              <si-number-input
                class="form-control"
                formControlName="fellowPassengers"
                [readonly]="readonly"
              />
            </si-form-item>
            <si-form-fieldset label="FORM.ACCEPT_TERMS">
              <si-form-item label="FORM.ACCEPT_TERMS_DESCRIPTION">
                <input
                  type="checkbox"
                  class="form-check-input"
                  id="termsAccepted"
                  formControlName="termsAccepted"
                  required
                />
                <button
                  si-help-button
                  type="button"
                  siHelpTitle="FORM.INPUT_HELP_TITLE"
                  siHelpContent="FORM.INPUT_HELP_DESCRIPTION"
                  >{{ 'FORM.ACCEPT_TERMS_MORE_INFORMATION' | translate }}</button
                >
              </si-form-item>
              <si-form-item label="FORM.ACCEPT_NO_PRIVACY">
                <input
                  type="checkbox"
                  class="form-check-input"
                  id="privacyDeclined"
                  formControlName="privacyDeclined"
                  required
                />
              </si-form-item>
            </si-form-fieldset>
            <div class="d-flex justify-content-end mt-6">
              <button type="button" class="btn btn-secondary me-6" (click)="cancel()"
                >Cancel</button
              >
              <button type="submit" class="btn btn-primary">Save</button>
            </div>
          </form>
        </div>
      </si-card>
    </div>
    <app-form-debug
      [formData]="form.getRawValue()"
      [submitted]="submitted"
      [validationStatus]="form.status"
      [(state)]="debugState"
    />
  </div>
</div>
```

##### Template-driven Form

Component:

```typescript
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { Component, Directive, effect, inject, input, signal } from '@angular/core';
import {
  AbstractControl,
  FormsModule,
  NG_VALIDATORS,
  NgForm,
  ValidationErrors,
  Validator,
  Validators
} from '@angular/forms';
import { SiCardComponent } from '@siemens/element-ng/card';
import {
  DateRange,
  SiCalendarButtonComponent,
  SiDatepickerDirective,
  SiDateRangeComponent,
  SiTimepickerComponent
} from '@siemens/element-ng/datepicker';
import { provideFormValidationErrorMapper, SiFormModule } from '@siemens/element-ng/form';
import { SiHelpButtonComponent } from '@siemens/element-ng/help-button';
import { SiNumberInputComponent } from '@siemens/element-ng/number-input';
import { PhoneDetails, SiPhoneNumberInputComponent } from '@siemens/element-ng/phone-number';
import { SelectOption, SiSelectModule } from '@siemens/element-ng/select';

import { SiFormDebugComponent } from './si-form-debug';

type Role = 'ENGINEER' | 'INSTALLER';

interface TravelRequest {
  name: string;
  role: Role | null;
  description: string;
  phoneNumber: PhoneDetails | null;
  birthday: Date | string;
  travelDate: DateRange | null;
  arrival: Date | null;
  departure: Date | null;
  serviceClass: string;
  fellowPassengers: number;
  termsAccepted: boolean;
  privacyDeclined: boolean;
}

const createEmptyRequest = (): TravelRequest => ({
  name: '',
  role: null,
  description: '',
  phoneNumber: null,
  birthday: '',
  travelDate: null,
  arrival: null,
  departure: null,
  serviceClass: 'first',
  fellowPassengers: 0,
  termsAccepted: false,
  privacyDeclined: false
});

@Directive({
  selector: '[appDepartureAfter]',
  providers: [
    {
      provide: NG_VALIDATORS,
      useFactory: () => inject(DepartureAfterValidatorDirective),
      multi: true
    }
  ]
})
export class DepartureAfterValidatorDirective implements Validator {
  readonly arrival = input<Date | null>(null, { alias: 'appDepartureAfter' });
  private validatorChange?: () => void;

  constructor() {
    effect(() => {
      this.arrival();
      this.validatorChange?.();
    });
  }

  validate(control: AbstractControl): ValidationErrors | null {
    const arrival = this.arrival();
    const departure: unknown = control.value;
    return arrival instanceof Date &&
      departure instanceof Date &&
      departure.getTime() < arrival.getTime()
      ? { departureTime: true }
      : null;
  }

  registerOnValidatorChange(fn: () => void): void {
    this.validatorChange = fn;
  }
}

@Directive({
  selector: '[appNoEconomy]',
  providers: [
    {
      provide: NG_VALIDATORS,
      useFactory: () => inject(NoEconomyValidatorDirective),
      multi: true
    }
  ]
})
export class NoEconomyValidatorDirective implements Validator {
  validate(control: AbstractControl): ValidationErrors | null {
    return control.value === 'economy' ? { noEconomy: true } : null;
  }
}

@Directive({
  selector: '[appMinimumFellowPassengers]',
  providers: [
    {
      provide: NG_VALIDATORS,
      useFactory: () => inject(MinimumFellowPassengersValidatorDirective),
      multi: true
    }
  ]
})
export class MinimumFellowPassengersValidatorDirective implements Validator {
  private readonly validator = Validators.min(2);

  validate(control: AbstractControl): ValidationErrors | null {
    return this.validator(control);
  }
}

@Directive({
  selector: '[appMinimumAge]',
  providers: [
    {
      provide: NG_VALIDATORS,
      useFactory: () => inject(MinimumAgeValidatorDirective),
      multi: true
    }
  ]
})
export class MinimumAgeValidatorDirective implements Validator {
  validate(control: AbstractControl): ValidationErrors | null {
    const value: unknown = control.value;
    if (!value) {
      return null;
    }

    const birthday = value instanceof Date ? value : new Date(value as string);
    if (isNaN(birthday.getTime())) {
      return null;
    }

    return Date.now() - birthday.getTime() >= 18 * 31556952000 ? null : { notEighteen: value };
  }
}

@Component({
  selector: 'app-sample',
  imports: [
    FormsModule,
    DepartureAfterValidatorDirective,
    MinimumFellowPassengersValidatorDirective,
    MinimumAgeValidatorDirective,
    NoEconomyValidatorDirective,
    SiCardComponent,
    SiCalendarButtonComponent,
    SiDatepickerDirective,
    SiDateRangeComponent,
    SiFormDebugComponent,
    SiFormModule,
    SiHelpButtonComponent,
    SiNumberInputComponent,
    SiPhoneNumberInputComponent,
    SiSelectModule,
    SiTimepickerComponent
  ],
  templateUrl: './si-template-driven-form.html',
  providers: [
    provideFormValidationErrorMapper({
      'name.pattern': 'Name must start with an uppercase letter.',
      'name.required': 'Required',
      'role.required': 'Required',
      'birthday.required': 'Required',
      'birthday.notEighteen': 'You must be at least 18 years old.',
      'travelDate.required': 'Travel date is required.',
      'arrival.required': 'Required',
      'departure.required': 'Required',
      'departure.departureTime': 'The departure time must be after arrival.',
      'serviceClass.noEconomy': 'You deserve better!',
      'fellowPassengers.min': 'Min. 2',
      'termsAccepted.required': 'You need to accept all terms before joining.',
      'privacyDeclined.required': 'Required'
    })
  ],
  host: { class: 'p-5' }
})
export class SampleComponent {
  protected readonly optionsList: SelectOption<string>[] = [
    {
      type: 'option',
      value: 'first',
      icon: 'element-face-happy',
      iconColor: 'status-success',
      label: 'First class'
    },
    {
      type: 'option',
      value: 'business',
      icon: 'element-face-neutral',
      iconColor: 'status-warning',
      label: 'Business'
    },
    {
      type: 'option',
      value: 'economy',
      icon: 'element-face-unhappy',
      iconColor: 'status-danger',
      label: 'Economy'
    }
  ];

  protected model = createEmptyRequest();
  protected submitted?: TravelRequest;
  protected readonly debugState = signal({ disabled: false, readonly: false });

  protected save(form: NgForm): void {
    if (form.invalid) {
      form.control.markAllAsTouched();
      return;
    }

    this.submitted = structuredClone(this.model);
  }

  protected cancel(form: NgForm): void {
    this.model = this.submitted ? structuredClone(this.submitted) : createEmptyRequest();
    form.resetForm(this.model);
  }
}
```

Template:

```html
<div class="container-fluid">
  <div class="row gy-5">
    <div class="col-12 col-md">
      <si-card heading="Template-driven Form">
        <div class="card-body" body>
          <form #form="ngForm" class="responsive-form-col-layout" (ngSubmit)="save(form)">
            <si-form-fieldset label="Role" inline>
              <si-form-item label="Engineer">
                <input
                  type="radio"
                  class="form-check-input"
                  name="role"
                  value="ENGINEER"
                  required
                  [disabled]="debugState().disabled || debugState().readonly"
                  [(ngModel)]="model.role"
                />
              </si-form-item>
              <si-form-item label="Installer">
                <input
                  type="radio"
                  class="form-check-input"
                  name="role"
                  value="INSTALLER"
                  required
                  [disabled]="debugState().disabled || debugState().readonly"
                  [(ngModel)]="model.role"
                />
              </si-form-item>
              <button
                si-help-button
                type="button"
                siHelpTitle="More information"
                siHelpContent="A role must be selected."
                >More information about the role</button
              >
            </si-form-fieldset>

            <si-form-item label="Name">
              <input
                type="text"
                class="form-control"
                name="name"
                required
                minlength="3"
                pattern="^[A-Z].*"
                [disabled]="debugState().disabled"
                [readonly]="debugState().readonly"
                [(ngModel)]="model.name"
              />
              <button
                si-help-button
                type="button"
                siHelpTitle="More information"
                siHelpContent="Full name must start with an uppercase letter and be at least 3 characters long."
                >More information about the name</button
              >
            </si-form-item>

            <si-form-item label="Description">
              <input
                type="text"
                class="form-control"
                name="description"
                [disabled]="debugState().disabled"
                [readonly]="debugState().readonly"
                [(ngModel)]="model.description"
              />
            </si-form-item>

            <si-form-item label="Phone number">
              <si-phone-number-input
                class="form-control"
                name="phoneNumber"
                defaultCountry="CH"
                placeholderForSearch="Search"
                selectCountryAriaLabel="Select country"
                [disabled]="debugState().disabled"
                [readonly]="debugState().readonly"
                [supportedCountries]="['AU', 'CH', 'DE', 'FK', 'IN', 'US']"
                [(ngModel)]="model.phoneNumber"
              />
            </si-form-item>

            <si-form-item label="Day of birth">
              <si-calendar-button class="w-100">
                <input
                  type="text"
                  class="w-100 form-control"
                  name="birthday"
                  autocomplete="off"
                  appMinimumAge
                  siDatepicker
                  required
                  [disabled]="debugState().disabled"
                  [readonly]="debugState().readonly"
                  [(ngModel)]="model.birthday"
                />
              </si-calendar-button>
            </si-form-item>

            <si-form-item label="Travel Date">
              <si-date-range
                class="w-100"
                name="travelDate"
                required
                [disabled]="debugState().disabled"
                [readonly]="debugState().readonly"
                [(ngModel)]="model.travelDate"
              />
            </si-form-item>

            <si-form-item label="Arrival">
              <si-timepicker
                name="arrival"
                required
                [disabled]="debugState().disabled"
                [hideLabels]="true"
                [readonly]="debugState().readonly"
                [(ngModel)]="model.arrival"
              />
            </si-form-item>

            <si-form-item label="Departure">
              <si-timepicker
                name="departure"
                required
                [appDepartureAfter]="model.arrival"
                [disabled]="debugState().disabled"
                [hideLabels]="true"
                [readonly]="debugState().readonly"
                [(ngModel)]="model.departure"
              />
            </si-form-item>

            <si-form-item label="Class of service">
              <si-select
                class="form-control"
                name="serviceClass"
                appNoEconomy
                [disabled]="debugState().disabled"
                [options]="optionsList"
                [readonly]="debugState().readonly"
                [(ngModel)]="model.serviceClass"
              />
            </si-form-item>

            <si-form-item label="Fellow passengers">
              <si-number-input
                class="form-control"
                name="fellowPassengers"
                appMinimumFellowPassengers
                [disabled]="debugState().disabled"
                [readonly]="debugState().readonly"
                [(ngModel)]="model.fellowPassengers"
              />
            </si-form-item>

            <si-form-fieldset label="Accept terms">
              <si-form-item label="I confirm that I accept all and everything.">
                <input
                  type="checkbox"
                  class="form-check-input"
                  name="termsAccepted"
                  required
                  [disabled]="debugState().disabled || debugState().readonly"
                  [(ngModel)]="model.termsAccepted"
                />
                <button
                  si-help-button
                  type="button"
                  siHelpTitle="More information"
                  siHelpContent="Acceptance of the terms and conditions is required."
                  >More information about the terms</button
                >
              </si-form-item>
              <si-form-item label="I confirm that I do not care about my privacy.">
                <input
                  type="checkbox"
                  class="form-check-input"
                  name="privacyDeclined"
                  required
                  [disabled]="debugState().disabled || debugState().readonly"
                  [(ngModel)]="model.privacyDeclined"
                />
              </si-form-item>
            </si-form-fieldset>

            <div class="d-flex justify-content-end mt-6">
              <button type="button" class="btn btn-secondary me-6" (click)="cancel(form)">
                Cancel
              </button>
              <button type="submit" class="btn btn-primary">Save</button>
            </div>
          </form>
        </div>
      </si-card>
    </div>

    <app-form-debug
      [formData]="form.value"
      [submitted]="submitted"
      [validationStatus]="form.status"
      [(state)]="debugState"
    />
  </div>
</div>
```

### Si-Form-Container (deprecated)

The `si-form-container` is an optional wrapper around a form. It provides additional responsive behavior for switching labels dependent on the available size from `block` (label is on top the input) to `inline` (label is on the same line).

### Angular Formly

Formly is a library for generating dynamic forms based on JSON input instead of pre-constructed HTML templates. Consider using formly for forms whose fields are not known at compile time and instead are created dynamically based on data. Element provides a built-in theming for [formly](<https://formly.dev/>) which is part of the `si-formly` component. See also [Dynamic Forms](<https://element.siemens.io/architecture/dynamic-forms/>).

### Native HTML markup

> Element does not recommend using native markup.

The Element theme includes a few CSS classes that are also internally used by the `si-form-item`. Internally, a form field is basically structured like this:

```
<div>
  <label class="form-label" for="input">Label</label>
  <input class="form-control" id="input" />
</div>
```

For checkboxes and radios, it uses `form-check` instead of the `form-control` class:

```
<div class="form-check mb-2">
  <input class="form-check-input" id="input" type="checkbox|radio" />
  <label class="form-check-label" for="input">Label</label>
</div>
```

In both variants the feedback is included using a `*-feedback` class. The feedback is either visible if an Angular state matches the feedback like `.ng-invalid` or if the state is set manually by applying a class like `.is-invalid`.

```
<div>
  <label class="form-label" for="input">Label</label>
  <input class="form-control is-invalid" id="input" />
  <div class="invalid-feedback">Invalid feedback</div>
</div>
```

### [SiFormContainerComponent](<https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-container/si-form-container.component.ts#L75-L202>)

**Kind:** component

**Selector:** `si-form-container`

```
import { SiFormContainerComponent } from '@siemens/element-ng/form';
```

Deprecated: This component should no longer be used.

When providing a form wide error mapper, use the [provideFormValidationErrorMapper](<../../../api/siemens/element-ng/types/provideFormValidationErrorMapper/index.html#t:provideFormValidationErrorMapper>).

```ts
import { provideFormValidationErrorMapper } form '@siemens/element-ng/forms'

@Component({
  template: `<form>...</form>`
  providers: [provideFormValidationErrorMapper({
    'name.required': 'CUSTOM_REQUIRED_ERROR'
  })]
})
class MyFormComponent {}
```

When using the column layout, use the `form-col-layout` classes.

```html
<!-- Responsive column layout -->
<form class="responsive-form-col-layout">...</form>
<!-- Always column layout -->
<form class="form-col-layout">...</form>
```

For a custom breakpoint use the SCSS mixin:

```scss
@use '@siemens/element-theme/src/styles/bootstrap/mixins/form-layout';

// Custom responsive breakpoint
.custom-form-col-layout {
  // Above 400px the column layout is used
  @include form-layout.responsive-form-col-layout(400px);
}
```

```
component SiFormContainerComponent<TControl extends { [K in keyof TControl]: AbstractControl }>
```

#### Input Properties

<table>     <thead>       <tr>         <th>Name</th>         <th>Type</th> <th>Default</th>        <th>Description</th>       </tr>     </thead>     <tbody>         <tr id="SiFormContainerComponent.contentContainerBreakpoints">           <td class="api-column-name">                   <span data-api-type-target-for="SiFormContainerComponent.contentContainerBreakpoints" id="t:SiFormContainerComponent.contentContainerBreakpoints"></span>               <a href="https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-container/si-form-container.component.ts#L96-L96">contentContainerBreakpoints</a>           </td>           <td class="api-column-type">             <code><a href="index.html#t:Breakpoints">Breakpoints</a> | <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined">undefined</a></code>           </td>             <td class="api-column-default"></td>           <td class="api-column-description"><p>The container hosts the form within a siResizeContainer to configure the breakpoint for different screen sizes. Optionally, change the container breakpoints with the contentContainerBreakpoints input.</p></td>         </tr>         <tr id="SiFormContainerComponent.controlNameTranslateKeyMap">           <td class="api-column-name">                   <span data-api-type-target-for="SiFormContainerComponent.controlNameTranslateKeyMap" id="t:SiFormContainerComponent.controlNameTranslateKeyMap"></span>               <a href="https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-container/si-form-container.component.ts#L128-L128">controlNameTranslateKeyMap</a>           </td>           <td class="api-column-type">             <code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map">Map</a>&lt;<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>, <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>&gt;</code>           </td>             <td class="api-column-default">    <code>new Map&lt;string, string&gt;()</code> </td>           <td class="api-column-description"><p>A map the maps from control names of the form to their translate keys. The initial map is empty and the user is responsible to add the required translate keys.</p></td>         </tr>         <tr id="SiFormContainerComponent.disableContainerBreakpoints">           <td class="api-column-name">                   <span data-api-type-target-for="SiFormContainerComponent.disableContainerBreakpoints" id="t:SiFormContainerComponent.disableContainerBreakpoints"></span>               <a href="https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-container/si-form-container.component.ts#L105-L105">disableContainerBreakpoints</a>           </td>           <td class="api-column-type">             <code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code>           </td>             <td class="api-column-default">    <code>false</code> </td>           <td class="api-column-description"><p>In some scenarios, one may not want the form container to be responsible for the layout relevant <code>si-container-[xs|...]</code> classes, but let this be done by a different, nested component, e.g. by a group box. In these cases, the property should be set to true.</p></td>         </tr>         <tr id="SiFormContainerComponent.disableErrorPrinting">           <td class="api-column-name">                   <span data-api-type-target-for="SiFormContainerComponent.disableErrorPrinting" id="t:SiFormContainerComponent.disableErrorPrinting"></span>               <a href="https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-container/si-form-container.component.ts#L135-L135">disableErrorPrinting</a>           </td>           <td class="api-column-type">             <code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code>           </td>             <td class="api-column-default">    <code>false</code> </td>           <td class="api-column-description"><p>Disables the automatic error printing in all nested <a href="index.html#SiFormItemComponent">SiFormItemComponent</a>. Error printing will be enabled by default in v46.</p></td>         </tr>         <tr id="SiFormContainerComponent.errorCodeTranslateKeyMap">           <td class="api-column-name">                   <span data-api-type-target-for="SiFormContainerComponent.errorCodeTranslateKeyMap" id="t:SiFormContainerComponent.errorCodeTranslateKeyMap"></span>               <a href="https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-container/si-form-container.component.ts#L114-L116">errorCodeTranslateKeyMap</a>           </td>           <td class="api-column-type">             <code><a href="index.html#t:SiFormValidationErrorMapper">SiFormValidationErrorMapper</a> | <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map">Map</a>&lt;<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>, <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>&gt; | <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined">undefined</a></code>           </td>             <td class="api-column-default"></td>           <td class="api-column-description"><p>Every validation error has an errorCode. This map holds translate keys for error codes. The keys can be used to display a translated message for each validation error. The defaults old english readable key defaults for the Angular standard validators of the <code>Validators</code> class like <code>min</code>, <code>max</code> or <code>required</code>.</p><p>Use the input to set your own translate keys for the form validators you need.</p></td>         </tr>         <tr id="SiFormContainerComponent.form">           <td class="api-column-name">                   <span data-api-type-target-for="SiFormContainerComponent.form" id="t:SiFormContainerComponent.form"></span>               <a href="https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-container/si-form-container.component.ts#L80-L80">form</a>           </td>           <td class="api-column-type">             <code><a href="https://angular.dev/api/forms/FormGroup">FormGroup</a>&lt;TControl&gt; | <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined">undefined</a></code>           </td>             <td class="api-column-default"></td>           <td class="api-column-description"><p>Set the form entity to the container to enable the overall form validation on in the form container edit panel.</p></td>         </tr>         <tr id="SiFormContainerComponent.labelWidth">           <td class="api-column-name">                   <span data-api-type-target-for="SiFormContainerComponent.labelWidth" id="t:SiFormContainerComponent.labelWidth"></span>               <a href="https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-container/si-form-container.component.ts#L142-L142">labelWidth</a>           </td>           <td class="api-column-type">             <code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a> | <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined">undefined</a></code>           </td>             <td class="api-column-default"></td>           <td class="api-column-description"><p>A custom width value to be applied to all labels.</p><p>Example:</p><pre><code>labelWidth=&quot;100px&quot;.</code></pre></td>         </tr>         <tr id="SiFormContainerComponent.readonly">           <td class="api-column-name">                   <span data-api-type-target-for="SiFormContainerComponent.readonly" id="t:SiFormContainerComponent.readonly"></span>               <a href="https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-container/si-form-container.component.ts#L89-L89">readonly</a>           </td>           <td class="api-column-type">             <code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code>           </td>             <td class="api-column-default">    <code>false</code> </td>           <td class="api-column-description"><p>A form container in readonly mode is only displaying the form content without ability to change it. The edit panel with typically save and cancel buttons is hidden. Set to true to display the edit panel.</p></td>         </tr>     </tbody>   </table>

#### Attributes and Methods

##### invalidFormContainerMessage

[Source for invalidFormContainerMessage](<https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-container/si-form-container.component.ts#L191-L193>)

**Modifiers:** readonly

**Type:** `boolean`

Indicates whether the content editor message shall be styled as warning.

Returns: `true`, if [SiFormContainerComponent.userInteractedWithForm](<index.html#SiFormContainerComponent.userInteractedWithForm>) is true and the form is invalid.

##### userInteractedWithForm

[Source for userInteractedWithForm](<https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-container/si-form-container.component.ts#L172-L175>)

**Modifiers:** readonly

**Type:** `boolean`

Indicates whether the user interacted with the form.

Returns: `true`, if the user selected at least one form element and \[blurred\][https://developer.mozilla.org/en-US/docs/Web/API/Element/blur\_event](<https://developer.mozilla.org/en-US/docs/Web/API/Element/blur_event>) by losing focus again (e.g. by setting focus on another element), or by editing the content of a form element. Otherwise `false`.

##### validFormContainerMessage

[Source for validFormContainerMessage](<https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-container/si-form-container.component.ts#L182-L184>)

**Modifiers:** readonly

**Type:** `boolean`

Indicates whether content editor message shall be styled as success.

Returns: `true`, if [SiFormContainerComponent.userInteractedWithForm](<index.html#SiFormContainerComponent.userInteractedWithForm>) is true and the form is valid.

### [SiFormItemComponent](<https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-item/si-form-item.component.ts#L60-L254>)

**Kind:** component

**Selector:** `si-form-item`

```
import { SiFormItemComponent } from '@siemens/element-ng/form';
```

```
component SiFormItemComponent implements AfterContentInit, AfterContentChecked, OnChanges, OnInit, OnDestroy, SiFormFieldsetControl
```

#### Input Properties

<table>     <thead>       <tr>         <th>Name</th>         <th>Type</th> <th>Default</th>        <th>Description</th>       </tr>     </thead>     <tbody>         <tr id="SiFormItemComponent.disableErrorPrinting">           <td class="api-column-name">                   <span data-api-type-target-for="SiFormItemComponent.disableErrorPrinting" id="t:SiFormItemComponent.disableErrorPrinting"></span>               <a href="https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-item/si-form-item.component.ts#L91-L91">disableErrorPrinting</a>           </td>           <td class="api-column-type">             <code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code>           </td>             <td class="api-column-default">    <code>false</code> </td>           <td class="api-column-description"><p>Disables the automatic error printing. Error printing will be enabled by default in v46.</p></td>         </tr>         <tr id="SiFormItemComponent.formErrorMapper">           <td class="api-column-name">                   <span data-api-type-target-for="SiFormItemComponent.formErrorMapper" id="t:SiFormItemComponent.formErrorMapper"></span>               <a href="https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-item/si-form-item.component.ts#L94-L94">formErrorMapper</a>           </td>           <td class="api-column-type">             <code><a href="index.html#t:SiFormValidationErrorMapper">SiFormValidationErrorMapper</a> | <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined">undefined</a></code>           </td>             <td class="api-column-default"></td>           <td class="api-column-description"><p>Maps validation errors of the contained control to custom messages.</p></td>         </tr>         <tr id="SiFormItemComponent.label">           <td class="api-column-name">                   <span data-api-type-target-for="SiFormItemComponent.label" id="t:SiFormItemComponent.label"></span>               <a href="https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-item/si-form-item.component.ts#L73-L73">label</a> (required)          </td>           <td class="api-column-type">             <code><a href="index.html#t:TranslatableString">TranslatableString</a></code>           </td>             <td class="api-column-default"></td>           <td class="api-column-description"><p>The label to be displayed in the form item. It will be translated if a translation key is available.</p></td>         </tr>         <tr id="SiFormItemComponent.labelWidth">           <td class="api-column-name">                   <span data-api-type-target-for="SiFormItemComponent.labelWidth" id="t:SiFormItemComponent.labelWidth"></span>               <a href="https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-item/si-form-item.component.ts#L84-L84">labelWidth</a>           </td>           <td class="api-column-type">             <code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a> | <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a> | <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined">undefined</a></code>           </td>             <td class="api-column-default"></td>           <td class="api-column-description"><p>A custom width value to be applied to the label. A value of 0 is allowed as well to visually hide away the label area.</p><p>Numbers will be converted to pixels. Using numbers is discouraged and might be dropped.</p><p>Example:</p><pre><code>labelWidth=&quot;100px&quot;</code></pre></td>         </tr>         <tr id="SiFormItemComponent.required">           <td class="api-column-name">                   <span data-api-type-target-for="SiFormItemComponent.required" id="t:SiFormItemComponent.required"></span>               <a href="https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-item/si-form-item.component.ts#L102-L102">required</a>           </td>           <td class="api-column-type">             <code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code>           </td>             <td class="api-column-default">    <code>false</code> </td>           <td class="api-column-description"><p>Defines that this form item is required for the overall form to be valid.</p></td>         </tr>     </tbody>   </table>

### Types Documentation

### [Breakpoints](<https://github.com/siemens/element/blob/main/projects/element-ng/resize-observer/si-responsive-container.directive.ts#L10-L16>)

**Kind:** interface

```
import type { Breakpoints } from '@siemens/element-ng/resize-observer';
```

```
interface Breakpoints
```

#### Properties

| Name | Type | Description |
| --- | --- | --- |
| [lgMinimum](<https://github.com/siemens/element/blob/main/projects/element-ng/resize-observer/si-responsive-container.directive.ts#L13-L13>) | `number` |  |
| [mdMinimum](<https://github.com/siemens/element/blob/main/projects/element-ng/resize-observer/si-responsive-container.directive.ts#L12-L12>) | `number` |  |
| [smMinimum](<https://github.com/siemens/element/blob/main/projects/element-ng/resize-observer/si-responsive-container.directive.ts#L11-L11>) | `number` |  |
| [xlMinimum](<https://github.com/siemens/element/blob/main/projects/element-ng/resize-observer/si-responsive-container.directive.ts#L14-L14>) | `number` |  |
| [xxlMinimum](<https://github.com/siemens/element/blob/main/projects/element-ng/resize-observer/si-responsive-container.directive.ts#L15-L15>) | `number` |  |

### [SiFormValidationErrorMapper](<https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-validation-error.model.ts#L12-L31>)

**Kind:** interface

```
import type { SiFormValidationErrorMapper } from '@siemens/element-ng/form';
```

Interface for form error mapper. It resolves a key to either a translatable string or function which is called with the validation error for its key and should return a translatable string.

```
interface SiFormValidationErrorMapper
```

#### Properties

| Name | Type | Description |
| --- | --- | --- |
| [dateFormat](<https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-validation-error.model.ts#L26-L26>) (optional) | `TranslatableString \| ((error: { format: string; }) => TranslatableString)` |  |
| [email](<https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-validation-error.model.ts#L15-L15>) (optional) | `TranslatableString \| ((error: { email: boolean; }) => TranslatableString)` |  |
| [max](<https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-validation-error.model.ts#L17-L17>) (optional) | `TranslatableString \| ((error: { max: number; actual: number; }) => TranslatableString)` |  |
| [maxDate](<https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-validation-error.model.ts#L27-L27>) (optional) | `TranslatableString \| ((error: { max: Date; actual: Date; }) => TranslatableString)` |  |
| [maxLength](<https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-validation-error.model.ts#L21-L23>) (optional) | `TranslatableString \| ((error: { requiredLength: number; actualLength: number; }) => TranslatableString)` |  |
| [min](<https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-validation-error.model.ts#L16-L16>) (optional) | `TranslatableString \| ((error: { min: number; actual: number; }) => TranslatableString)` |  |
| [minDate](<https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-validation-error.model.ts#L28-L28>) (optional) | `TranslatableString \| ((error: { min: Date; actual: Date; }) => TranslatableString)` |  |
| [minLength](<https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-validation-error.model.ts#L18-L20>) (optional) | `TranslatableString \| ((error: { requiredLength: number; actualLength: number; }) => TranslatableString)` |  |
| [numberFormat](<https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-validation-error.model.ts#L25-L25>) (optional) | `TranslatableString \| ((error: { numberFormat: boolean; }) => TranslatableString)` |  |
| [pattern](<https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-validation-error.model.ts#L24-L24>) (optional) | `TranslatableString \| ((error: { pattern: string \| RegExp; }) => TranslatableString)` |  |
| [required](<https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-validation-error.model.ts#L13-L13>) (optional) | `TranslatableString \| ((error: { required: boolean; }) => TranslatableString)` |  |
| [requiredTrue](<https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-validation-error.model.ts#L14-L14>) (optional) | `TranslatableString \| ((error: { required: boolean; }) => TranslatableString)` |  |

#### Index Signatures

| Name | Type | Description |
| --- | --- | --- |
| [\[key: string\]](<https://github.com/siemens/element/blob/main/projects/element-ng/form/si-form-validation-error.model.ts#L30-L30>) | `string \| ((error: any) => string) \| undefined` |  |

### [TranslatableString](<https://github.com/siemens/element/blob/main/projects/element-translate-ng/translate-types/global.types.ts#L18-L18>)

**Kind:** type alias

```
import type { TranslatableString } from '@siemens/element-translate-ng/translate-types';
```

Represents a translatable string. This can either be a translation key, e.g. `ACTIONS.EDIT` that will be automatically translated when displayed on the UI or a pre-translated string, e.g. `Edit`. Equivalent to a normal string in usage and functionality.

```
type TranslatableString = string & Translatable
```

### [SiFormFieldsetControl](<https://github.com/siemens/element/blob/main/projects/element-ng/form/form-fieldset/si-form-fieldset.control.ts#L9-L15>)

**Kind:** interface

```
interface SiFormFieldsetControl
```

#### Properties

| Name | Type | Description |
| --- | --- | --- |
| [control](<https://github.com/siemens/element/blob/main/projects/element-ng/form/form-fieldset/si-form-fieldset.control.ts#L10-L10>) (readonly) | `Signal<unknown>` |  |
| [errors](<https://github.com/siemens/element/blob/main/projects/element-ng/form/form-fieldset/si-form-fieldset.control.ts#L14-L14>) (readonly) | `Signal<readonly SiFormError[]>` |  |
| [radioGroupName](<https://github.com/siemens/element/blob/main/projects/element-ng/form/form-fieldset/si-form-fieldset.control.ts#L11-L11>) (optional, readonly) | `Signal<string \| undefined>` |  |
| [required](<https://github.com/siemens/element/blob/main/projects/element-ng/form/form-fieldset/si-form-fieldset.control.ts#L12-L12>) (readonly) | `Signal<boolean>` |  |
| [touched](<https://github.com/siemens/element/blob/main/projects/element-ng/form/form-fieldset/si-form-fieldset.control.ts#L13-L13>) (readonly) | `Signal<boolean>` |  |
