Skip to content

Commit 6e68b64

Browse files
FormStore ToObject fixed. (#102)
1 parent c752cd1 commit 6e68b64

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

packages/react-forms/src/stores/form-store.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -662,29 +662,38 @@ export class FormStore extends ActionEmitter {
662662
protected BuildFormObject(fieldsGroupId?: string): Dictionary {
663663
const result: Dictionary = {};
664664

665-
const groupFields = this.State.Fields.filter(x =>
666-
x != null &&
667-
(x.FieldsGroup == null || x.FieldsGroup.Id === fieldsGroupId));
665+
const groupFields = this.State.Fields.filter(x => {
666+
// If the field is null (never)
667+
if (x == null) {
668+
return false;
669+
}
670+
671+
if (x.FieldsGroup == null) {
672+
return fieldsGroupId == null;
673+
} else {
674+
return x.FieldsGroup.Id === fieldsGroupId;
675+
}
676+
});
668677

669678
groupFields.forEach((field, fieldId) => {
670-
if (field == null || field == null) {
679+
if (field == null || fieldId == null) {
671680
return;
672681
}
673682
result[field.Name] = field.Value;
674683
});
675684

676685
const fieldsGroups = this.State.FieldsGroups.filter(x => x != null && x.Parent === fieldsGroupId);
677-
fieldsGroups.forEach((fieldsGroup, index) => {
678-
if (fieldsGroup == null || index == null) {
686+
fieldsGroups.forEach((fieldsGroup, fieldId) => {
687+
if (fieldsGroup == null || fieldId == null) {
679688
return;
680689
}
681690
if (fieldsGroup.ArrayName != null) {
682691
if (result[fieldsGroup.ArrayName] == null) {
683692
result[fieldsGroup.ArrayName] = [];
684693
}
685-
result[fieldsGroup.ArrayName].push(this.BuildFormObject(index));
694+
result[fieldsGroup.ArrayName].push(this.BuildFormObject(fieldId));
686695
} else {
687-
result[fieldsGroup.Name] = this.BuildFormObject(index);
696+
result[fieldsGroup.Name] = this.BuildFormObject(fieldId);
688697
}
689698
});
690699
return result;

0 commit comments

Comments
 (0)