From a287f4cf85d40ef436a3cf4f80aa877d9f8d29b9 Mon Sep 17 00:00:00 2001 From: Michael Aziz Date: Tue, 8 Apr 2025 15:20:52 +0200 Subject: [PATCH] [SYNC] --- lib/src/form/src/controller.dart | 69 ++++++++++++++++---------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/lib/src/form/src/controller.dart b/lib/src/form/src/controller.dart index 5711bcc..945df5b 100644 --- a/lib/src/form/src/controller.dart +++ b/lib/src/form/src/controller.dart @@ -315,52 +315,53 @@ class AstromicFormController extends FormController { // } void initializeFormGroup(FormGroupStructure groupStructure, {int initialCount = 1}) { - assert(groupStructure.fields.isNotEmpty, '${groupStructure.id}: Group fields should NOT be empty.'); + assert(groupStructure.fields.isNotEmpty, '${groupStructure.id}: Group fields should NOT be empty.'); - // Validate subgroups (if any) - _validateSubGroups(groupStructure); + // Validate subgroups (if any) + _validateSubGroups(groupStructure); - // Add structure to registry - _formGroups.add(groupStructure); + // Add structure to registry + _formGroups.add(groupStructure); - // Initialize the group instances - _initializeGroupControllers(groupStructure, initialCount); - } + // Initialize the group instances + _initializeGroupControllers(groupStructure, initialCount); +} - /// Recursively initialize controllers for the group and its subgroups - void _initializeGroupControllers(FormGroupStructure groupStructure, int initialCount, {String parentPrefix = ''}) { - // Add main group fields/values - for (int groupIndex = 0; groupIndex < initialCount; groupIndex++) { - _addGroupControllers(groupStructure, groupIndex, parentPrefix: parentPrefix); +/// Recursively initialize controllers for the group and its subgroups +void _initializeGroupControllers(FormGroupStructure groupStructure, int initialCount, {String parentPrefix = ''}) { + // Add main group fields/values + for (int groupIndex = 0; groupIndex < initialCount; groupIndex++) { + _addGroupControllers(groupStructure, groupIndex, parentPrefix: parentPrefix); - // Recursively handle subgroups - if (groupStructure.subGroups != null && groupStructure.subGroups!.isNotEmpty) { - for (final (FormGroupStructure subGroup, int subgroupInitialCount) in groupStructure.subGroups!) { - final String nestedPrefix = parentPrefix.isEmpty - ? standeredGroupFormat(groupStructure.id, groupIndex, subGroup.id) // If no parentPrefix, use the group directly - : '$parentPrefix->${standeredGroupFormat(groupStructure.id, groupIndex, subGroup.id)}'; // Add to parentPrefix + // Recursively handle subgroups + if (groupStructure.subGroups != null && groupStructure.subGroups!.isNotEmpty) { + for (final (FormGroupStructure subGroup, int subgroupInitialCount) in groupStructure.subGroups!) { + final String subgroupPrefix = parentPrefix.isEmpty + ? standeredGroupFormat(groupStructure.id, groupIndex, subGroup.id) + : '$parentPrefix->${standeredGroupFormat(groupStructure.id, groupIndex, subGroup.id)}'; // Add to parentPrefix only once - // Initialize subgroup controllers recursively - for (int subIndex = 0; subIndex < subgroupInitialCount; subIndex++) { - _initializeGroupControllers(subGroup, subgroupInitialCount, parentPrefix: nestedPrefix); - } + // Initialize subgroup controllers recursively + for (int subIndex = 0; subIndex < subgroupInitialCount; subIndex++) { + _initializeGroupControllers(subGroup, subgroupInitialCount, parentPrefix: subgroupPrefix); } } } } +} - /// Validate subgroups recursively - void _validateSubGroups(FormGroupStructure groupStructure) { - groupStructure.subGroups?.forEach((subGroupTuple) { - final subGroup = subGroupTuple.$1; - assert(subGroup.fields.isNotEmpty, '${subGroup.id}: Subgroup fields should NOT be empty.'); +/// Validate subgroups recursively +void _validateSubGroups(FormGroupStructure groupStructure) { + groupStructure.subGroups?.forEach((subGroupTuple) { + final subGroup = subGroupTuple.$1; + assert(subGroup.fields.isNotEmpty, '${subGroup.id}: Subgroup fields should NOT be empty.'); + + // Recursively validate subgroups of subgroups + if (subGroup.subGroups != null) { + _validateSubGroups(subGroup); + } + }); +} - // Recursively validate subgroups of subgroups - if (subGroup.subGroups != null) { - _validateSubGroups(subGroup); - } - }); - } // void initializeFormGroup(FormGroupStructure groupStructure, {int initialCount = 1}) { // assert(groupStructure.fields.isNotEmpty, '$groupStructure: Group Fields should NOT be empty.');