[SYNC]
This commit is contained in:
@@ -468,32 +468,63 @@ class AstromicFormController extends FormController {
|
||||
}
|
||||
}
|
||||
|
||||
bool validateGroup(String groupID, {Map<String, int>? parents}) {
|
||||
(List<String> fields, List<String> values) _checkSubgroupsToValidate(String groupID, {Map<String, int>? parents}) {
|
||||
FormGroupStructure? groupStructure = getGroupStructure(groupID);
|
||||
String? prefix;
|
||||
if (parents != null) {
|
||||
prefix = parents.entries.map((MapEntry<String, int> parentEntry) => standeredGroupFormat(parentEntry.key, parentEntry.value.toString(), null)).join('-');
|
||||
}
|
||||
//
|
||||
//
|
||||
List<String> fieldsToValidate = <String>[];
|
||||
List<String> valuesToValidate = <String>[];
|
||||
for ((int, FormGroupStructure) sg in (groupStructure?.subGroups ?? <(int, FormGroupStructure)>[])) {
|
||||
FormGroupStructure? subgroupStructure = getGroupStructure(sg.$2.id);
|
||||
int sgInstances = getInstanceCount(sg.$2.id, parents: <String, int>{...?parents});
|
||||
for (int i = 0; i < sgInstances; i++) {
|
||||
_checkSubgroupsToValidate(
|
||||
sg.$2.id,
|
||||
parents: <String, int>{
|
||||
...?parents,
|
||||
...<String, int>{sg.$2.id: i}
|
||||
},
|
||||
);
|
||||
for (String fieldID in subgroupStructure!.fields) {
|
||||
fieldsToValidate.add(standeredGroupFormat((prefix != null ? '$prefix-' : '') + sg.$2.id, i.toString(), fieldID));
|
||||
}
|
||||
for (String valueID in (subgroupStructure.values ?? <String>[])) {
|
||||
valuesToValidate.add(standeredGroupFormat((prefix != null ? '$prefix-' : '') + sg.$2.id, i.toString(), valueID));
|
||||
}
|
||||
}
|
||||
}
|
||||
return (fieldsToValidate, valuesToValidate);
|
||||
}
|
||||
|
||||
/// Validate the group with ID.
|
||||
bool validateGroup(String groupID) {
|
||||
// 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);
|
||||
int currentGroupInstances = getInstanceCount(groupID);
|
||||
|
||||
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));
|
||||
fieldsToValidate.add(standeredGroupFormat(groupID, i.toString(), fieldID));
|
||||
}
|
||||
for (String valueID in (groupStructure.values ?? <String>[])) {
|
||||
valuesToValidate.add((prefix != null ? '$prefix-' : '') + standeredGroupFormat(groupID, i.toString(), valueID));
|
||||
valuesToValidate.add(standeredGroupFormat(groupID, i.toString(), valueID));
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Loop through the subgroups and get their fields and values
|
||||
(List<String> fields, List<String> values) sgRet = _checkSubgroupsToValidate(groupID, parents: <String, int>{groupID: i});
|
||||
fieldsToValidate.addAll(sgRet.$1);
|
||||
valuesToValidate.addAll(sgRet.$2);
|
||||
} //
|
||||
return validateOnly(fieldsToValidate) && validateValues(valuesToValidate);
|
||||
}
|
||||
//!SECTION
|
||||
|
||||
Reference in New Issue
Block a user