From 4ca0272d1e0c3aa5ad17769bd48ebb4e9a0082bd Mon Sep 17 00:00:00 2001 From: Michael Aziz Date: Tue, 8 Apr 2025 16:31:35 +0200 Subject: [PATCH] [SYNC] --- lib/src/form/src/controller.dart | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/src/form/src/controller.dart b/lib/src/form/src/controller.dart index ec3a6f9..7b60036 100644 --- a/lib/src/form/src/controller.dart +++ b/lib/src/form/src/controller.dart @@ -196,10 +196,22 @@ class AstromicFormController extends FormController { } int getInstanceCount(String targetGroupID) { + String? p = getFullPathOfGroup(targetGroupID); + if (p != null && p.split('->').length > 1 && p.split('->').indexOf(targetGroupID) != 0) { + // This is a subgroup + } FormGroupStructure? structure = getGroupStructure(targetGroupID); if (structure != null) { String firstField = structure.fields.first; - return controllers.keys.where((String c) => RegExp(standeredGroupFormat(targetGroupID, r'[\d+]', firstField)).hasMatch(c)).nonNulls.toList().length; + // return controllers.keys.where((String c) => RegExp(standeredGroupFormat(targetGroupID, r'[\d+]', firstField)).hasMatch(c)).nonNulls.toList().length; + return controllers.keys + .where((String c) { + // Match the specific group ID and field name within the group + final RegExp pattern = RegExp(r'^' + RegExp.escape(standeredGroupFormat(targetGroupID, r'[\d+]', firstField)) + r'(-#\d+)?$'); + return pattern.hasMatch(c); + }) + .nonNulls + .toList().length; } return 0; }