@bnsights/bbsf-controls 1.2.5 → 1.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2287,6 +2287,53 @@ class ControlFilterItem {
2287
2287
  }
2288
2288
 
2289
2289
  class CustomValidation {
2290
+ /**
2291
+ * Gets the control name from its parent FormGroup
2292
+ * @param control The AbstractControl to get the name for
2293
+ * @returns The control name/key or null if not found
2294
+ */
2295
+ static getControlName(control) {
2296
+ if (!control || !control.parent) {
2297
+ return null;
2298
+ }
2299
+ const parent = control.parent;
2300
+ if (!(parent instanceof FormGroup)) {
2301
+ return null;
2302
+ }
2303
+ // Iterate through parent's controls to find the one that matches
2304
+ const formGroup = parent;
2305
+ for (const key in formGroup.controls) {
2306
+ if (formGroup.controls[key] === control) {
2307
+ return key;
2308
+ }
2309
+ }
2310
+ return null;
2311
+ }
2312
+ /**
2313
+ * Extracts the element index from a control name in repeater pattern
2314
+ * Pattern: fieldName.itemIndex.controlIndex
2315
+ * @param control The AbstractControl to extract index from
2316
+ * @returns The element index (itemIndex) or null if not found
2317
+ *
2318
+ * @example
2319
+ * // Before (Angular < 19):
2320
+ * elementIndex = control?.nativeElement?.id?.split(".")[1];
2321
+ *
2322
+ * // After (Angular 19+):
2323
+ * elementIndex = CustomValidation.getElementIndex(control);
2324
+ */
2325
+ static getElementIndex(control) {
2326
+ const controlName = this.getControlName(control);
2327
+ if (!controlName) {
2328
+ return null;
2329
+ }
2330
+ // Split by "." and get the second part (itemIndex)
2331
+ const parts = controlName.split('.');
2332
+ if (parts.length >= 2) {
2333
+ return parts[1];
2334
+ }
2335
+ return null;
2336
+ }
2290
2337
  }
2291
2338
  class CustomValidator {
2292
2339
  // Number only validation