This commit is contained in:
2025-04-15 11:56:55 +02:00
parent 55e56dd874
commit 41a129db44

View File

@@ -467,6 +467,35 @@ class AstromicFormController extends FormController {
switchValuesFirst: true);
}
}
bool validateGroup(String groupID, {Map<String, int>? 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<String, int> 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<String> fieldsToValidate = <String>[];
List<String> valuesToValidate = <String>[];
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 ?? <String>[])) {
valuesToValidate.add((prefix != null ? '$prefix-' : '') + standeredGroupFormat(groupID, i.toString(), valueID));
}
}
//
return validateOnly(fieldsToValidate) && validateValues(valuesToValidate);
}
//!SECTION
//SECTION - Helper Methods