Skip to content

Commit 68a56c4

Browse files
Angular Form: Add formData Angular Signals Support Info (#8749)
1 parent deb9f00 commit 68a56c4

2 files changed

Lines changed: 81 additions & 2 deletions

File tree

api-reference/10 UI Components/dxForm/1 Configuration/formData.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ firedEvents: fieldDataChanged
99
Provides the Form's data. Gets updated every time form fields change.
1010

1111
---
12+
13+
---
14+
15+
##### Angular
16+
17+
[note] **formData** does not support Angular signals. For more information, refer to the following topic: [DevExtreme Angular - Using Angular Signals with DevExtreme](/Documentation/Guide/Angular_Components/Common_Features/Using_Angular_Signals_with_DevExtreme/).
18+
19+
---
20+
1221
#include btn-open-demo with {
1322
href: "https://js.devexpress.com/Demos/WidgetsGallery/Demo/Common/FormsAndMultiPurpose/Overview/"
1423
}

concepts/40 Angular Components/40 Common Features/20 Using Angular Signals with DevExtreme.md

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,77 @@ If you want to integrate this capability into your application, you can examine
1414
}
1515

1616
* The `prefix` signal in the example monitors the state of the "Prefix" dropdown. When the user changes the active option, the corresponding `effect` function filters the list of employees, and selects rows with employees that match the selected prefix.
17-
* The `selectedRows` signal monitors the state of the table and reports changes to the row selection.
18-
* The `selectionMessage` computed signal listens to the `selectedRows` signal. It joins the names of the selected employees into a single string. The table caption includes this string.
17+
* `selectedRows` monitors the state of the table and reports changes to the row selection.
18+
* `selectionMessage` listens to the `selectedRows` signal. It joins the names of the selected employees into a single string. The table caption includes this string.
19+
20+
[note]
21+
22+
**dxForm**.[formData](/Documentation/ApiReference/UI_Components/dxForm/Configuration/#formData) does not support signals. To use signals with **formData**, implement one of the following:
23+
24+
- Create a new object bound to a signal and synchronize this object with **formData** in [onFieldDataChanged](/Documentation/ApiReference/UI_Components/dxForm/Configuration/#onFieldDataChanged):
25+
26+
<!-- tab: app.component.html -->
27+
<dx-form
28+
[formData]="formData"
29+
(onFieldDataChanged)="handleFieldDataChanged($event)"
30+
></dx-form>
31+
32+
<!-- tab: app.component.ts -->
33+
import { Component, signal } from "@angular/core";
34+
import { DxFormModule, type DxFormTypes } from "devextreme-angular/ui/form";
35+
36+
// ...
37+
export class AppComponent {
38+
formData = { firstName: "John", lastName: "Doe", age: 30 };
39+
formDataSignal = signal({ ...this.formData });
40+
handleFieldDataChanged(e: DxFormTypes.FieldDataChangedEvent): void {
41+
if (!e.dataField) return;
42+
this.formDataSignal.set({ ...this.formData });
43+
}
44+
}
45+
46+
47+
- Configure item [templates](/Documentation/ApiReference/UI_Components/dxForm/Item_Types/SimpleItem/#template) for all dxForm fields and bind signals to each component's **value** property:
48+
49+
<!-- tab: app.component.html -->
50+
<dx-form>
51+
<dxi-form-item itemType="simple" dataField="firstName">
52+
<div *dxTemplate>
53+
<dx-text-box
54+
[value]="formDataSignal().firstName"
55+
(onValueChanged)="updateField('firstName', $event.value)"
56+
></dx-text-box>
57+
</div>
58+
</dxi-form-item>
59+
<dxi-form-item itemType="simple" dataField="lastName">
60+
<div *dxTemplate>
61+
<dx-text-box
62+
[value]="formDataSignal().lastName"
63+
(onValueChanged)="updateField('lastName', $event.value)"
64+
></dx-text-box>
65+
</div>
66+
</dxi-form-item>
67+
<dxi-form-item itemType="simple" dataField="age">
68+
<div *dxTemplate>
69+
<dx-number-box
70+
[value]="formDataSignal().age"
71+
(onValueChanged)="updateField('age', $event.value)"
72+
></dx-number-box>
73+
</div>
74+
</dxi-form-item>
75+
</dx-form>
76+
77+
<!-- tab: app.component.ts -->
78+
import { Component, signal } from "@angular/core";
79+
80+
// ...
81+
export class AppComponent {
82+
formDataSignal = signal({ firstName: "John", lastName: "Doe", age: 30 });
83+
updateField(field: string, value: any) {
84+
this.formDataSignal.update((d) => ({ ...d, [field]: value }));
85+
}
86+
}
87+
88+
[/note]
1989

2090
[tags] angular

0 commit comments

Comments
 (0)