[SYNC]
This commit is contained in:
@@ -235,7 +235,7 @@ class AstromicFormController extends FormController {
|
|||||||
return '${groupStructure.id}-#${firstSetOfFieldsWithID.length}-';
|
return '${groupStructure.id}-#${firstSetOfFieldsWithID.length}-';
|
||||||
}
|
}
|
||||||
|
|
||||||
String removeInstanceFromFormGroup(String formGroupID, int indexToRemove, {bool isSubGroup = false}) {
|
void removeInstanceFromFormGroup(String formGroupID, int indexToRemove, {bool isSubGroup = false}) {
|
||||||
// Get the group structure with the same ID
|
// Get the group structure with the same ID
|
||||||
FormGroupStructure? groupStructure;
|
FormGroupStructure? groupStructure;
|
||||||
if (isSubGroup) {
|
if (isSubGroup) {
|
||||||
@@ -257,7 +257,7 @@ class AstromicFormController extends FormController {
|
|||||||
controllers.entries.where((MapEntry<String, String> c) => RegExp(formGroupID + r'-#[\d+]-' + groupStructure!.fields.first).hasMatch(c.key)).nonNulls.toList(),
|
controllers.entries.where((MapEntry<String, String> c) => RegExp(formGroupID + r'-#[\d+]-' + groupStructure!.fields.first).hasMatch(c.key)).nonNulls.toList(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (i >= firstSetOfFieldsWithID.length) {
|
if (indexToRemove >= firstSetOfFieldsWithID.length) {
|
||||||
throw Exception('The index to remove is larger than the whole instances count.');
|
throw Exception('The index to remove is larger than the whole instances count.');
|
||||||
} else {
|
} else {
|
||||||
// get the fields IDs
|
// get the fields IDs
|
||||||
@@ -267,35 +267,32 @@ class AstromicFormController extends FormController {
|
|||||||
List<String> valuesIDs = groupStructure.values?.nonNulls.toList() ?? <String>[];
|
List<String> valuesIDs = groupStructure.values?.nonNulls.toList() ?? <String>[];
|
||||||
print('valueIDs: $valuesIDs');
|
print('valueIDs: $valuesIDs');
|
||||||
|
|
||||||
if (i == (firstSetOfFieldsWithID.length - 1)) {
|
if (indexToRemove == (firstSetOfFieldsWithID.length - 1)) {
|
||||||
// Remove the last item
|
// Remove the last item
|
||||||
for (String fieldID in groupStructure.fields) {
|
for (String fieldID in groupStructure.fields) {
|
||||||
removeController('${groupStructure.id}-#$i-$fieldID');
|
removeController('${groupStructure.id}-#$indexToRemove-$fieldID');
|
||||||
}
|
}
|
||||||
if (groupStructure.values != null && groupStructure.values!.isNotEmpty) {
|
if (groupStructure.values != null && groupStructure.values!.isNotEmpty) {
|
||||||
for (String valueID in groupStructure.values!) {
|
for (String valueID in groupStructure.values!) {
|
||||||
removeController('${groupStructure.id}-#$i-$valueID');
|
removeController('${groupStructure.id}-#$indexToRemove-$valueID');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Switch and remove
|
// Switch and remove
|
||||||
int nextIndex = i + 1;
|
int nextIndex = indexToRemove + 1;
|
||||||
for (String fieldID in groupStructure.fields) {
|
for (String fieldID in groupStructure.fields) {
|
||||||
set('${groupStructure.id}-#$i-$fieldID', value('${groupStructure.id}-#$nextIndex-$fieldID'));
|
set('${groupStructure.id}-#$indexToRemove-$fieldID', value('${groupStructure.id}-#$nextIndex-$fieldID'));
|
||||||
removeController('${groupStructure.id}-#$nextIndex-$fieldID');
|
removeController('${groupStructure.id}-#$nextIndex-$fieldID');
|
||||||
}
|
}
|
||||||
if (groupStructure.values != null && groupStructure.values!.isNotEmpty) {
|
if (groupStructure.values != null && groupStructure.values!.isNotEmpty) {
|
||||||
for (String valueID in groupStructure.values!) {
|
for (String valueID in groupStructure.values!) {
|
||||||
set('${groupStructure.id}-#$i-$valueID', value('${groupStructure.id}-#$nextIndex-$valueID'));
|
set('${groupStructure.id}-#$indexToRemove-$valueID', value('${groupStructure.id}-#$nextIndex-$valueID'));
|
||||||
removeController('${groupStructure.id}-#$nextIndex-$valueID');
|
removeController('${groupStructure.id}-#$nextIndex-$valueID');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the controllers and values.
|
|
||||||
|
|
||||||
return '${groupStructure.id}-#${firstSetOfFieldsWithID.length}-';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// void removeFromFormGroup(String formGroupID, int index) {
|
// void removeFromFormGroup(String formGroupID, int index) {
|
||||||
|
|||||||
Reference in New Issue
Block a user