From 41a129db44d5550fcbebc66eb9e7206c3e8b1e13 Mon Sep 17 00:00:00 2001 From: Michael Aziz Date: Tue, 15 Apr 2025 11:56:55 +0200 Subject: [PATCH] [SYNC] --- lib/src/form/src/controller.dart | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/src/form/src/controller.dart b/lib/src/form/src/controller.dart index d02f323..ae18f60 100644 --- a/lib/src/form/src/controller.dart +++ b/lib/src/form/src/controller.dart @@ -467,6 +467,35 @@ class AstromicFormController extends FormController { switchValuesFirst: true); } } + + bool validateGroup(String groupID, {Map? parents}) { + // Get tha main targeted group's structure + FormGroupStructure? groupStructure = getGroupStructure(groupID); + assert(groupStructure != null, 'The Group $groupID doesn\'t seem to be found, are you sure you initialized it?'); + + // Get the prefix for subgroups if exists + String? prefix; + if (isASubGroup(groupID) && parents != null) { + prefix = parents.entries.map((MapEntry parentEntry) => standeredGroupFormat(parentEntry.key, parentEntry.value.toString(), null)).join('-'); + } + + // Get current instances of this group and the new index. + int currentGroupInstances = getInstanceCount(groupID, parents: parents); + + List fieldsToValidate = []; + List valuesToValidate = []; + for (int i = 0; i < currentGroupInstances; i++) { + for (String fieldID in groupStructure!.fields) { + fieldsToValidate.add((prefix != null ? '$prefix-' : '') + standeredGroupFormat(groupID, i.toString(), fieldID)); + } + for (String valueID in (groupStructure.values ?? [])) { + valuesToValidate.add((prefix != null ? '$prefix-' : '') + standeredGroupFormat(groupID, i.toString(), valueID)); + } + } + + // + return validateOnly(fieldsToValidate) && validateValues(valuesToValidate); + } //!SECTION //SECTION - Helper Methods