# Dynamic forms

Element supports dynamic forms using [Angular Formly](<https://formly.dev/>) which allows to generate forms from JSON data.

> [!NOTE]
>
> **Formly version**
>
> The `@siemens/element-ng/formly` package is based on Angular Formly v7.1. If you are still using Formly v6, use `@siemens/element-ng/formly-legacy` instead.

> [!WARNING]
>
> **Migrate from `formly-legacy`**
>
> `@siemens/element-ng/formly-legacy` (Formly v6) is deprecated and support will be dropped in a future release. Migrate to `@siemens/element-ng/formly` (Formly v7.1) as soon as possible.

## Code

### Usage

> [!NOTE]
>
> **Required Packages**
>
> - [@ngx-formly/core](<https://www.npmjs.com/package/@ngx-formly/core>)
> - [@ngx-formly/bootstrap](<https://www.npmjs.com/package/@ngx-formly/bootstrap>)

```
import { SiFormlyComponent } from '@siemens/element-ng/formly';

@Component({
  imports: [SiFormlyComponent, ...]
})
```

### Standalone support

`SiFormlyComponent` is a standalone component. Import it directly into your component's `imports` and register any custom types/validators/wrappers via `provideFormlyCore` in your app configuration.

```
import { ApplicationConfig } from '@angular/core';
import { provideFormlyCore } from '@ngx-formly/core';

const config: ApplicationConfig = {
  providers: [
    provideFormlyCore({
      // optionally you can add following configurations
      types: [
        // register your custom types here
      ],
      validators: [
        // register your custom validators here
      ],
      wrappers: [
        // register your custom wrapper here
      ]
    })
  ]
}
```

### SiFormlyComponent

The `SiFormlyComponent` is a wrapper around formly to generate dynamic forms. Please note that if you don't use this wrapper your form items will not be themed correctly based on Element theme and you might have to manually manage theming which is not recommended.

#### Example

Component:

```typescript
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
import { FormRecord } from '@angular/forms';
import { FormlyFieldConfig, FormlyFormOptions } from '@ngx-formly/core';
import { DatepickerInputConfig } from '@siemens/element-ng/datepicker';
import { SiFormModule } from '@siemens/element-ng/form';
import { SiFormlyComponent } from '@siemens/element-ng/formly';

@Component({
  selector: 'app-sample',
  imports: [CommonModule, SiFormModule, SiFormlyComponent],
  templateUrl: './si-dynamic-form-fields.html'
})
export class SampleComponent {
  form = new FormRecord({});
  dateConfig: DatepickerInputConfig = {
    minDate: new Date('8.5.2021'),
    showTime: true,
    showSeconds: true,
    mandatoryTime: true
  };
  model = {
    text: 'lorem ipsum',
    textIcon: 'Input with icon for additional information tooltip',
    numberInput: 5.5,
    password: 'dolor',
    email: 'john.doe@example.org',
    textarea: 'lorem\nipsum\ndolor',
    checkbox: true,
    multiCheckbox: {
      '#1': true,
      '#2': false,
      '#3': true,
      '#4': false
    },
    numberNew: 20,
    radio: '#3',
    customSelectMultiSelect: ['good', 'poor'],
    select: 'reykjavik',
    date: new Date(),
    datetime: '2021-08-12T05:22:54Z',
    time: new Date('2021-08-12T05:22:54'),
    textdisplay: 'Read only text',
    daterange: {
      start: new Date('2021-08-12T05:22:54Z'),
      end: new Date(new Date('2021-08-12T05:22:54Z').setFullYear(new Date().getFullYear() + 1))
    },
    customSelect: undefined,
    ipV4Address: '192.168.0.1',
    ipV4AddressCIDR: '192.168.0.1/24',
    ipV6Address: '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
    ipV6CIDRAddress: '2001:0db8:85a3:0000:0000:8a2e:0370:7334/64',
    card_text: 'sample card body value'
  };
  tmpFields: FormlyFieldConfig[] = [
    {
      key: 'textdisplay',
      type: 'textdisplay',
      wrappers: ['form-field'],
      props: {
        label: 'Display only text'
      }
    },
    {
      key: 'text',
      type: 'input',
      props: {
        required: true,
        label: 'Text input'
      },
      validation: {
        show: true,
        messages: {
          required: (error, field: FormlyFieldConfig) => {
            return `Please enter some text`;
          }
        }
      }
    },
    {
      key: 'textIcon',
      type: 'input',
      wrappers: ['form-field', 'icon-wrapper'],
      props: {
        label: 'Icon input',
        icon: 'element-link',
        iconSize: 20, // defaults to 20px
        iconTooltip: 'Translatable Text like "foo.bar.SOME_KEY"'
      }
    },
    {
      key: 'numberInput',
      type: 'input',
      props: {
        type: 'number',
        label: 'Number input',
        min: 0,
        max: 100,
        step: 0.1
      }
    },
    {
      key: 'password',
      type: 'password',
      props: {
        type: 'password',
        required: true,
        label: 'Password input'
      },
      validation: {
        show: true,
        messages: {
          required: (error, field: FormlyFieldConfig) => {
            return `Please enter a password`;
          },
          siPasswordStrength: (error, field: FormlyFieldConfig) => {
            return `Please enter a stronger password`;
          }
        }
      }
    },
    {
      key: 'email',
      type: 'input',
      props: {
        type: 'email',
        label: 'Email input'
      }
    },
    {
      key: 'numberNew',
      type: 'number',
      props: {
        type: 'number',
        label: 'Number Input',
        numberStep: 0.2,
        showButtons: true
      }
    },
    {
      template: '<hr>'
    },
    {
      template: `
        <p>The date and datetime component is derived from <code>SiDatePickerComponent</code>
        and supports same configurations as <code>SiDatePickerInputConfig</code></p>
        <p>The fields are displaying their model value in local time zone</p>
      `
    },
    {
      key: 'date',
      type: 'date',
      props: {
        label: 'Date',
        dateFormat: 'date'
      }
    },
    {
      key: 'datetime',
      type: 'datetime',
      props: {
        label: 'Datetime',
        placeholder: 'Enter a date',
        dateConfig: this.dateConfig,
        required: true
      },
      validation: {
        show: true,
        messages: {
          required: (error, field: FormlyFieldConfig) => {
            return `Please enter a date`;
          },
          invalidMinDate: (error, field: FormlyFieldConfig) => {
            return `Please enter a date after ${error.min}`;
          }
        }
      }
    },
    {
      key: 'daterange',
      type: 'date-range',
      props: {
        label: 'Daterange',
        startPlaceholder: 'Enter start date',
        endPlaceholder: 'Enter end date',
        autoClose: true,
        siDatepickerConfig: {
          enableTwoMonthDateRange: true,
          showTime: true,
          showSeconds: false,
          showMilliseconds: false,
          disabledTime: true,
          mandatoryTime: false
        }
      }
    },
    {
      template: `
        <p>The time component is derived from <code>SiTimepickerComponent</code>
        <p>The fields are displaying their model value in local time zone</p>
      `
    },
    {
      key: 'time',
      type: 'time',
      props: {
        label: 'Time',
        timeConfig: {
          showSeconds: true,
          showMilliseconds: true,
          showMeridian: undefined
        }
      }
    },
    {
      template: '<hr>'
    },
    {
      key: 'textarea',
      type: 'textarea',
      props: {
        autoGrow: true,
        resizable: true,
        maxHeight: '100px',
        label: 'Textarea'
      }
    },
    {
      key: 'checkbox',
      type: 'checkbox',
      props: {
        label: 'Checkbox'
      }
    },
    {
      key: 'checkbox_left',
      type: 'checkbox',
      props: {
        label: 'Checkbox #2',
        labelWidth: 1
      }
    },
    {
      template: '<hr>'
    },
    {
      key: 'multiCheckbox',
      type: 'multicheckbox',
      props: {
        label: 'Multi-Checkbox',
        options: [
          { label: 'Option #1', value: '#1' },
          { label: 'Option #2', value: '#2' },
          { label: 'Option #3', value: '#3' },
          { label: 'Option #4', value: '#4' }
        ]
      }
    },
    {
      template: '<hr>'
    },
    {
      key: 'radio',
      type: 'radio',
      props: {
        label: 'Radio',
        options: [
          { label: 'Option #1', value: '#1' },
          { label: 'Option #2', value: '#2' },
          { label: 'Option #3', value: '#3' },
          { label: 'Option #4', value: '#4' }
        ]
      }
    },
    {
      template: '<hr>'
    },
    {
      key: 'customSelect',
      type: 'si-select',
      props: {
        type: 'si-select',
        required: true,
        label: 'si-select',
        optionsList: [
          {
            type: 'option',
            value: 'good',
            icon: 'element-face-happy',
            iconColor: 'status-success',
            label: 'Good'
          },
          {
            type: 'option',
            value: 'average',
            icon: 'element-face-neutral',
            iconColor: 'status-warning',
            label: 'Average'
          },
          {
            type: 'option',
            value: 'poor',
            icon: 'element-face-unhappy',
            iconColor: 'status-danger',
            label: 'Poor'
          },
          {
            type: 'option',
            value: 'unhealthy',
            icon: 'element-face-very-unhappy',
            iconColor: 'status-critical',
            label: 'Unhealthy',
            disabled: true
          }
        ]
      },
      validation: {
        show: true,
        messages: {
          required: (error, field: FormlyFieldConfig) => {
            return `Please choose an option`;
          }
        }
      }
    },
    {
      key: 'customSelectMultiSelect',
      type: 'si-select',
      props: {
        type: 'si-select',
        label: 'si-select multi',
        multi: true,
        hasFilter: true,
        optionsList: [
          {
            type: 'option',
            value: 'good',
            icon: 'element-face-happy',
            iconColor: 'status-success',
            label: 'Good'
          },
          {
            type: 'option',
            value: 'average',
            icon: 'element-face-neutral',
            iconColor: 'status-warning',
            label: 'Average'
          },
          {
            type: 'option',
            value: 'poor',
            icon: 'element-face-unhappy',
            iconColor: 'status-danger',
            label: 'Poor'
          },
          {
            type: 'option',
            value: 'unhealthy',
            icon: 'element-face-very-unhappy',
            iconColor: 'status-critical',
            label: 'Unhealthy',
            disabled: true
          }
        ]
      }
    },
    {
      key: 'select',
      type: 'select',
      props: {
        label: 'Select',
        options: [
          { label: 'Rome', value: 'rome' },
          { label: 'Berlin', value: 'berlin' },
          { label: 'Reykjavík', value: 'reykjavik' },
          { label: 'Helsinki', value: 'helsinki' }
        ]
      }
    },
    {
      template: '<hr>'
    },
    {
      key: 'ipV4Address',
      type: 'ipv4',
      props: {
        label: 'IPv4 Address',
        placeholder: 'Enter a IPv4 address',
        required: true
      },
      validation: {
        show: true,
        messages: {
          required: (error, field: FormlyFieldConfig) => {
            return `Please enter a IPv4 address`;
          },
          ipv4Address: (error, field: FormlyFieldConfig) => {
            return `Invalid IPv4 address`;
          }
        }
      }
    },
    {
      key: 'ipV4AddressCIDR',
      type: 'ipv4',
      props: {
        cidr: true,
        label: 'IPv4 Address with CIDR',
        placeholder: 'Enter a IPv4 address with subnet mask',
        required: true
      },
      validation: {
        show: true,
        messages: {
          required: (error, field: FormlyFieldConfig) => {
            return `Please enter a IPv4 address`;
          },
          ipv4Address: (error, field: FormlyFieldConfig) => {
            return `Invalid IPv4 CIDR address`;
          }
        }
      }
    },
    {
      key: 'ipV6Address',
      type: 'ipv6',
      props: {
        label: 'IPv6 Address',
        placeholder: 'Enter a IPv6 address',
        required: true
      },
      validation: {
        show: true,
        messages: {
          required: (error, field: FormlyFieldConfig) => {
            return `Please enter a IPv6 address`;
          },
          ipv6Address: (error, field: FormlyFieldConfig) => {
            return `Invalid IPv6 address`;
          }
        }
      }
    },
    {
      key: 'ipV6CIDRAddress',
      type: 'ipv6',
      props: {
        label: 'IPv6 CIDR Address',
        cidr: true,
        placeholder: 'Enter a IPv6 address',
        required: true
      },
      validation: {
        show: true,
        messages: {
          required: (error, field: FormlyFieldConfig) => {
            return `Please enter a IPv6 address`;
          },
          ipv6Address: (error, field: FormlyFieldConfig) => {
            return `Invalid IPv6 address`;
          }
        }
      }
    },
    {
      template: '<hr><h2>Buttons</h2>'
    },
    {
      key: 'btn_func',
      type: 'button',
      className: 'd-block mb-4',
      props: {
        hideLabel: true, // Hide wrapper label
        label: 'Button function handler',
        clickListener: (a: string, b: string) => {
          alert(
            `Button with function as listener receiving configurable Params a: "${a}" and b: "${b}"`
          );
        },
        clickArgs: ['stringParam', 42]
      }
    },
    {
      key: 'btn_exp',
      type: 'button',
      className: 'd-block mb-4',
      props: {
        hideLabel: true, // Hide wrapper label
        label: 'Button expression handler',
        clickListener: 'formState.btnClicked',
        clickArgs: ['1st', 23]
      }
    },
    {
      key: 'btn_prim',
      type: 'button',
      className: 'd-block mb-4',
      props: {
        hideLabel: true, // Hide wrapper label
        label: 'Primary',
        clickListener: 'formState.btnClicked',
        clickArgs: ['primary', 23],
        btnType: 'primary'
      }
    },
    {
      key: 'btn_sec',
      type: 'button',
      className: 'd-block mb-4',
      props: {
        hideLabel: true, // Hide wrapper label
        label: 'Secondary (Default)',
        clickListener: 'formState.btnClicked',
        clickArgs: ['secondary', 23],
        btnType: 'secondary'
      }
    },
    {
      key: 'btn_tert',
      type: 'button',
      className: 'd-block mb-4',
      props: {
        hideLabel: true, // Hide wrapper label
        label: 'Tertiary',
        clickListener: 'formState.btnClicked',
        clickArgs: ['tertiary', 23],
        btnType: 'tertiary'
      }
    },
    {
      key: 'btn_warn',
      type: 'button',
      className: 'd-block mb-4',
      props: {
        hideLabel: true, // Hide wrapper label
        label: 'Warning',
        clickListener: 'formState.btnClicked',
        clickArgs: ['warning', 23],
        btnType: 'warning'
      }
    },
    {
      key: 'btn_danger',
      type: 'button',
      className: 'd-block mb-4',
      props: {
        hideLabel: true, // Hide wrapper label
        label: 'Danger',
        clickListener: 'formState.btnClicked',
        clickArgs: ['danger', 23],
        btnType: 'danger'
      }
    },
    {
      template: '<hr><h2>Custom Wrapper</h2>'
    },
    {
      key: 'card_text',
      type: 'textdisplay',
      wrappers: ['custom-wrapper'],
      props: {
        heading: 'Sample card header'
      }
    }
  ];
  fieldsTmpl = JSON.parse(JSON.stringify(this.tmpFields));
  fields = this.tmpFields;
  options: FormlyFormOptions = {
    formState: {
      btnClicked: (a: string, b: string) => {
        alert(
          `Button with expression listener receiving configurable Params a: "${a}" and b: "${b}"`
        );
      }
    }
  };
}
```

Template:

```html
<div class="container-fluid p-5">
  <p>Showcase for all available standard components for input and output</p>
  <p
    >The form is completely configured in Typescript (See <em>Field configuration</em> at bottom)</p
  >
  <h1>Form</h1>
  <si-form-container [form]="form">
    <div si-form-container-content>
      <si-formly
        [labelWidth]="150"
        [fields]="fields"
        [model]="model"
        [form]="form"
        [options]="options"
      />
    </div>
  </si-form-container>
  <div class="e2e-ignore">
    <h1>Model</h1>
    <pre tabindex="0">{{ model | json }}</pre>
    <h1>Field configuration</h1>
    <p>Array of FormlyFieldConfig</p>
    <pre tabindex="0">{{ fieldsTmpl | json }}</pre>
  </div>
</div>
```

## Utilities

There are plenty of utilities custom-made for you to develop apps with dynamic forms using `SiFormly`.

### [Custom Types](<https://formly.dev/docs/guide/custom-formly-field>)

In addition to prebuilt types from bootstrap, Element also provides you with a set of custom types that help you to easily make use of Element components in formly. The below types helps you to develop your dynamic forms app more easily.

#### Structural types

These types can be used to achieve a specific layout or wrapper for your form elements.

- `object-grid`

  - Wraps your fields in a configurable bootstrap grid.
  - Use `gridConfig` property with props in [field config](<https://formly.dev/docs/api/core/#formlyfieldconfig>) to configure your grid.
- `array`

  - Wraps your form array together with add/remove buttons if needed.
  - Expects a field array type to be provided within the fields input.
- `accordion`

  - Wraps your input fields in an [accordion](<https://element.siemens.io/components/layout-navigation/accordion/>)
- `tabset`

  - Wraps your input fields in a [tabset](<https://element.siemens.io/components/layout-navigation/tabs/>)

#### Field types

In addition to the formly bootstrap types, the following custom types can be used to enable use of Element form components with formly.

- `checkbox`
- `button`

  Use `btnType` property with props in [field config](<https://formly.dev/docs/api/core/#formlyfieldconfig>) to configure following supported button types:

  - primary
  - secondary
  - tertiary
  - danger
  - warning
- `boolean`
- `date`

  The following inputs can be passed as [field config](<https://formly.dev/docs/api/core/#formlyfieldconfig>) props:

  - autoClose
  - dateConfig
- `date-range`

  The following inputs can be passed as [field config](<https://formly.dev/docs/api/core/#formlyfieldconfig>) props:

  - ariaLabelCalendarButton
  - autoClose
  - debounceTime
  - endDatePlaceholder
  - endTimeLabel
  - siDatepickerConfig
  - startDatePlaceholder
  - startTimeLabel
- `datetime`

  The following inputs can be passed as [field config](<https://formly.dev/docs/api/core/#formlyfieldconfig>) props:

  - autoClose
  - dateConfig
- `email`
- `enum`
- `integer`
- `number`

  The following inputs can be passed as [field config](<https://formly.dev/docs/api/core/#formlyfieldconfig>) props:

  - numberStep
  - showButtons
  - unit
- `password`

  The following inputs can be passed as [field config](<https://formly.dev/docs/api/core/#formlyfieldconfig>) props:

  - digits
  - lowerCase
  - minLength
  - special
  - upperCase
- `si-select`

  - use `multi` property with props in [field config](<https://formly.dev/docs/api/core/#formlyfieldconfig>) to enable multi selection mode.
- `string`
- `textdisplay`

  - use `prefix` property with props in [field config](<https://formly.dev/docs/api/core/#formlyfieldconfig>) to add prefix before text.
  - use `suffix` property with props in [field config](<https://formly.dev/docs/api/core/#formlyfieldconfig>) to add suffix after text.
- `textarea`
- `time`

  The following inputs can be passed as [field config](<https://formly.dev/docs/api/core/#formlyfieldconfig>) props:

  - hideLabels
  - showMeridian
  - showMilliseconds
  - showMinutes
  - showSeconds

### [Custom wrappers](<https://formly.dev/docs/guide/custom-formly-wrapper>)

Use following wrappers to wrap your form fields with specific Element components.

- `form-field`

  - uses `SiFormItemComponent` to wrap your form fields
- `form-fieldset`

  - uses `SiFormFieldsetComponent`
- `form-field-horizontal`

  - wraps your form field and label in a horizontal layout.
- `icon-wrapper`

  - wraps your form field with an icon displayed at the end.
  - The following inputs can be passed as [field config](<https://formly.dev/docs/api/core/#formlyfieldconfig>) props:

    - `icon`

      - the icon to be displayed at the end of the form field.
    - `iconSize`

      - the size of the icon to be displayed in pixels.
    - `iconTooltip`

      - Tooltip for the icon to be displayed.

### Grid layout

`SiFormly` also supports rendering form with multi column grid layout.

#### Example

Component:

```typescript
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { Component } from '@angular/core';
import { FormRecord } from '@angular/forms';
import { FormlyFieldConfig } from '@ngx-formly/core';
import { SiFormModule } from '@siemens/element-ng/form';
import { SiFormlyComponent } from '@siemens/element-ng/formly';

@Component({
  selector: 'app-sample',
  imports: [SiFormModule, SiFormlyComponent],
  templateUrl: './si-dynamic-form-grid.html'
})
export class SampleComponent {
  form = new FormRecord({});
  model = {
    firstname1: 'John',
    lastname1: 'Doe',
    email1: 'john.doe@example.org',
    firstname2: 'Johann Georg',
    lastname2: 'Halske',
    email2: 'j.g.halske@example.org',
    businessAddr: 'Sample address of John Doe',
    privateAddr: 'Private address of John Doe, Johann Georg Halske and their families'
  };
  fields: FormlyFieldConfig[] = [
    {
      type: 'object-grid',
      props: {
        // Config for a simple bootstrap grid
        gridConfig: [
          {
            //classes: [], // custom grid classes
            columns: [
              { fieldCount: 4 /*, classes: [] */ }, // custom classes instead of bootstrap grid
              { fieldCount: 4 }
            ]
          },
          {
            columns: [{ fieldCount: 1 }]
          },
          {
            columns: [
              { fieldCount: -1 } // -1 catches all remaining fields
            ]
          }
        ]
      },
      fieldGroup: [
        { template: '<b>Person 1<b/>' },
        {
          key: 'firstname1',
          type: 'input',
          props: {
            label: 'First name'
          }
        },
        {
          key: 'lastname1',
          type: 'input',
          props: {
            label: 'Last name'
          }
        },
        {
          key: 'email1',
          type: 'input',
          props: {
            label: 'Email'
          }
        },
        { template: '<b>Person 2<b/>' },
        {
          key: 'firstname2',
          type: 'input',
          props: {
            label: 'First name'
          }
        },
        {
          key: 'lastname2',
          type: 'input',
          props: {
            label: 'Last name'
          }
        },
        {
          key: 'email2',
          type: 'input',
          props: {
            label: 'Email'
          }
        },
        {
          key: 'privateAddr',
          type: 'textarea',
          props: {
            label: 'Private Address'
          }
        },
        {
          key: 'businessAddr',
          type: 'textarea',
          props: {
            label: 'Business Address'
          }
        }
      ]
    }
  ];
}
```

Template:

```html
<h1 class="p-5">Form</h1>
<si-form-container [form]="form">
  <div si-form-container-content>
    <si-formly [labelWidth]="100" [fields]="fields" [model]="model" [form]="form" />
  </div>
</si-form-container>
```

### Tabs

`SiFormly` also supports rendering form in multiple tabs. It uses `SiTabsetComponent` internally for displaying tabs.

#### Example

Component:

```typescript
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { Component } from '@angular/core';
import { FormRecord } from '@angular/forms';
import { FormlyFieldConfig, FormlyFormOptions } from '@ngx-formly/core';
import { SiFormModule } from '@siemens/element-ng/form';
import { SiFormlyComponent } from '@siemens/element-ng/formly';

@Component({
  selector: 'app-sample',
  imports: [SiFormModule, SiFormlyComponent],
  templateUrl: './si-dynamic-form-tabs.html',
  styleUrl: './si-dynamic-form-tabs.scss'
})
export class SampleComponent {
  form = new FormRecord({});
  model = {
    firstname: 'John Doe',
    lastname: 'Smith',
    email: 'john.doe@example.org',
    businessAddr: 'Sample address of John Doe',
    privateAddr: 'Sample private address of John Doe'
  };
  options: FormlyFormOptions = {
    formState: {
      // select the second tab as active by default
      selectedTabIndex: 1
    }
  };
  fields: FormlyFieldConfig[] = [
    {
      type: 'tabset',
      fieldGroup: [
        {
          props: {
            label: 'Personal'
          },
          fieldGroup: [
            {
              key: 'firstname',
              type: 'input',
              props: {
                label: 'First name'
              }
            },
            {
              key: 'lastname',
              type: 'input',
              props: {
                label: 'Last name'
              }
            },
            {
              key: 'email',
              type: 'input',
              props: {
                label: 'Email'
              }
            }
          ]
        },
        {
          props: {
            label: 'Address'
          },
          fieldGroup: [
            {
              key: 'privateAddr',
              type: 'textarea',
              props: {
                label: 'Private'
              }
            },
            {
              key: 'businessAddr',
              type: 'textarea',
              props: {
                label: 'Business'
              }
            }
          ]
        }
      ]
    }
  ];
}
```

Template:

```html
<h1 class="p-5">Form</h1>
<si-form-container [form]="form">
  <div si-form-container-content class="si-layout-fixed-height">
    <si-formly
      class="si-layout-fixed-height"
      [labelWidth]="250"
      [fields]="fields"
      [model]="model"
      [form]="form"
      [options]="options"
    />
  </div>
</si-form-container>
```

### Accordion

`SiFormly` also supports rendering forms in accordions. It makes use of `SiAccordionComponent` internally.

#### Example

Component:

```typescript
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { Component } from '@angular/core';
import { FormRecord } from '@angular/forms';
import { FormlyFieldConfig } from '@ngx-formly/core';
import { SiFormModule } from '@siemens/element-ng/form';
import { SiFormlyComponent } from '@siemens/element-ng/formly';

@Component({
  selector: 'app-sample',
  imports: [SiFormModule, SiFormlyComponent],
  templateUrl: './si-dynamic-form-accordion.html',
  styleUrl: './si-dynamic-form-tabs.scss'
})
export class SampleComponent {
  form = new FormRecord({});
  model = {
    firstname: 'John',
    lastname: 'Doe',
    email: 'john.d@example.org',
    businessAddr: 'Sample address',
    privateAddr: 'Sample private address of John Doe'
  };
  fields: FormlyFieldConfig[] = [
    {
      type: 'accordion',
      fieldGroup: [
        {
          props: {
            label: 'Personal'
          },
          fieldGroup: [
            {
              key: 'firstname',
              type: 'input',
              props: {
                label: 'First name'
              }
            },
            {
              key: 'lastname',
              type: 'input',
              props: {
                label: 'Last name'
              }
            },
            {
              key: 'email',
              type: 'input',
              props: {
                label: 'Email'
              }
            }
          ]
        },
        {
          props: {
            label: 'Address'
          },
          fieldGroup: [
            {
              key: 'privateAddr',
              type: 'textarea',
              props: {
                autoGrow: true,
                label: 'Private'
              }
            },
            {
              key: 'businessAddr',
              type: 'textarea',
              props: {
                autoGrow: true,
                label: 'Business'
              }
            }
          ]
        },
        {
          props: {
            label: 'Travel information'
          },
          fieldGroup: [
            {
              key: 'startDate',
              type: 'date',
              props: {
                label: 'Date of departure'
              }
            },
            {
              key: 'endDate',
              type: 'date',
              props: {
                label: 'Date of Arrival'
              }
            }
          ]
        }
      ]
    }
  ];
}
```

Template:

```html
<h1 class="p-5">Dynamic Forms - Accordion Type</h1>
<si-form-container [form]="form">
  <div si-form-container-content class="si-layout-fixed-height">
    <si-formly
      class="si-layout-fixed-height"
      [labelWidth]="250"
      [fields]="fields"
      [model]="model"
      [form]="form"
    />
  </div>
</si-form-container>
```

### i18n support

`SiFormly` internally uses a [custom extension](<https://formly.dev/docs/guide/custom-formly-extension>) `translate` to internationalize your forms.  
It is configured similar to [this doc on formly](<https://formly.dev/docs/examples/advanced/i18n-alternative>) but without the hard dependency to `ngx-translate` library.

### [SiFormlyComponent](<https://github.com/siemens/element/blob/main/projects/element-ng/formly/si-formly.component.ts#L42-L142>)

**Kind:** component

**Selector:** `si-formly`

```
import { SiFormlyComponent } from '@siemens/element-ng/formly';
```

```
component SiFormlyComponent<TControl extends { [K in keyof TControl]: AbstractControl }> implements OnInit
```

#### Input Properties

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [fields](<https://github.com/siemens/element/blob/main/projects/element-ng/formly/si-formly.component.ts#L82-L82>) | `FormlyFieldConfig<FormlyFieldProps & { [additionalProperties: string]: any; }>[]` | `[]` | Define all form fields with FormlyFieldConfig array. |
| [form](<https://github.com/siemens/element/blob/main/projects/element-ng/formly/si-formly.component.ts#L51-L51>) | `FormGroup<TControl> \| undefined` |  | Reactive form used by Formly. A form is created when none is provided. |
| [labelWidth](<https://github.com/siemens/element/blob/main/projects/element-ng/formly/si-formly.component.ts#L88-L88>) | `number \| undefined` |  | Width in pixels applied to field labels. |
| [model](<https://github.com/siemens/element/blob/main/projects/element-ng/formly/si-formly.component.ts#L60-L60>) | `{}` | `{}` | Mapping of field name and its value. |
| [options](<https://github.com/siemens/element/blob/main/projects/element-ng/formly/si-formly.component.ts#L69-L69>) | `FormlyFormOptions` | `{}` | Define FormlyFormOptions. |
| [schema](<https://github.com/siemens/element/blob/main/projects/element-ng/formly/si-formly.component.ts#L74-L74>) | `JSONSchema7 \| undefined` |  | JSONSchema7 can be used instead of FormlyFieldConfig array for defining form fields. |

#### Output Properties

| Name | Type | Description |
| --- | --- | --- |
| [fieldsChange](<https://github.com/siemens/element/blob/main/projects/element-ng/formly/si-formly.component.ts#L85-L85>) | `FormlyFieldConfig<FormlyFieldProps & { [additionalProperties: string]: any; }>[]` | Emits the effective field configuration, including configuration generated from `schema`. |
| [formChange](<https://github.com/siemens/element/blob/main/projects/element-ng/formly/si-formly.component.ts#L51-L51>) | `FormGroup<TControl> \| undefined` | Reactive form used by Formly. A form is created when none is provided. |
| [modelChange](<https://github.com/siemens/element/blob/main/projects/element-ng/formly/si-formly.component.ts#L60-L60>) | `{}` | Mapping of field name and its value. |
| [schemaChange](<https://github.com/siemens/element/blob/main/projects/element-ng/formly/si-formly.component.ts#L74-L74>) | `JSONSchema7 \| undefined` | JSONSchema7 can be used instead of FormlyFieldConfig array for defining form fields. |

#### Attributes and Methods

##### formlyForm

[Source for formlyForm](<https://github.com/siemens/element/blob/main/projects/element-ng/formly/si-formly.component.ts#L48-L48>)

**Modifiers:** readonly

**Type:** `Signal<FormlyForm | undefined>`

**Default:** `viewChild(FormlyForm)`

Formly main container to provide modelChange subscriptions.
