@suntelecoms/ngx-dynamic-form 1.5.1 → 1.6.1

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.
@@ -1,4 +1,4 @@
1
- import { OnInit } from '@angular/core';
1
+ import { EventEmitter, OnInit } from '@angular/core';
2
2
  import { FormControl, FormGroup } from '@angular/forms';
3
3
  import { DynamicFormField, SelectOption } from '../../models/form-field.model';
4
4
  import { PhoneCountry } from '../../data/phone-countries';
@@ -16,10 +16,17 @@ export declare class DynamicFieldComponent implements OnInit {
16
16
  get isSimple(): boolean;
17
17
  get resolvedFloatLabel(): 'auto' | 'always';
18
18
  private builder;
19
+ private evaluator;
19
20
  private http;
20
21
  private dataApiUrl;
21
22
  resolvedOptions: SelectOption[];
22
23
  loadingOptions: boolean;
24
+ lookupLoading: boolean;
25
+ /** Emitted on every value change of this field */
26
+ fieldChange: EventEmitter<{
27
+ key: string;
28
+ value: any;
29
+ }>;
23
30
  locating: boolean;
24
31
  locationError: string;
25
32
  readonly phoneCountries: PhoneCountry[];
@@ -63,6 +70,9 @@ export declare class DynamicFieldComponent implements OnInit {
63
70
  get hasOptions(): boolean;
64
71
  get hasError(): boolean;
65
72
  get errorMessage(): string | null;
73
+ private setupRequiredWhen;
74
+ private updateRequiredFromConditions;
75
+ onLookupBlur(): void;
66
76
  static ɵfac: i0.ɵɵFactoryDeclaration<DynamicFieldComponent, never>;
67
- static ɵcmp: i0.ɵɵComponentDeclaration<DynamicFieldComponent, "ngx-dynamic-field", never, { "field": { "alias": "field"; "required": true; }; "form": { "alias": "form"; "required": true; }; "formAppearance": { "alias": "formAppearance"; "required": false; }; "formFloatLabel": { "alias": "formFloatLabel"; "required": false; }; }, {}, never, never, true, never>;
77
+ static ɵcmp: i0.ɵɵComponentDeclaration<DynamicFieldComponent, "ngx-dynamic-field", never, { "field": { "alias": "field"; "required": true; }; "form": { "alias": "form"; "required": true; }; "formAppearance": { "alias": "formAppearance"; "required": false; }; "formFloatLabel": { "alias": "formFloatLabel"; "required": false; }; }, { "fieldChange": "fieldChange"; }, never, never, true, never>;
68
78
  }
@@ -15,6 +15,11 @@ export declare class DynamicFormComponent implements OnInit, OnChanges {
15
15
  formSubmit: EventEmitter<DynamicFormSubmitEvent>;
16
16
  /** Emitted on every value change */
17
17
  formChange: EventEmitter<Record<string, any>>;
18
+ /** Emitted on every individual field value change */
19
+ fieldChange: EventEmitter<{
20
+ key: string;
21
+ value: any;
22
+ }>;
18
23
  /** Emitted when form is reset */
19
24
  formReset: EventEmitter<void>;
20
25
  form: FormGroup;
@@ -36,5 +41,5 @@ export declare class DynamicFormComponent implements OnInit, OnChanges {
36
41
  */
37
42
  private normalizeValues;
38
43
  static ɵfac: i0.ɵɵFactoryDeclaration<DynamicFormComponent, never>;
39
- static ɵcmp: i0.ɵɵComponentDeclaration<DynamicFormComponent, "ngx-dynamic-form", never, { "config": { "alias": "config"; "required": true; }; "initialValues": { "alias": "initialValues"; "required": false; }; }, { "formSubmit": "formSubmit"; "formChange": "formChange"; "formReset": "formReset"; }, never, never, true, never>;
44
+ static ɵcmp: i0.ɵɵComponentDeclaration<DynamicFormComponent, "ngx-dynamic-form", never, { "config": { "alias": "config"; "required": true; }; "initialValues": { "alias": "initialValues"; "required": false; }; }, { "formSubmit": "formSubmit"; "formChange": "formChange"; "fieldChange": "fieldChange"; "formReset": "formReset"; }, never, never, true, never>;
40
45
  }
@@ -1,4 +1,4 @@
1
- import type { DynamicFormConfig, DynamicFormField, FieldCondition, FieldType, FieldValidation, SelectOption, StepperFormConfig } from '../../models/form-field.model';
1
+ import type { DynamicFormConfig, DynamicFormField, FieldCondition, FieldType, FieldValidation, SelectOption, StepGuard, StepperFormConfig } from '../../models/form-field.model';
2
2
  import * as i0 from "@angular/core";
3
3
  interface FieldTypeDef {
4
4
  type: FieldType;
@@ -10,6 +10,9 @@ interface BuilderStep {
10
10
  label: string;
11
11
  icon?: string;
12
12
  fields: DynamicFormField[];
13
+ atLeastOneOf?: string[];
14
+ atLeastOneOfMessage?: string;
15
+ beforeNext?: StepGuard;
13
16
  }
14
17
  export declare const ICON_OPTIONS: {
15
18
  value: string;
@@ -34,6 +37,8 @@ export declare class FormBuilderComponent {
34
37
  stepperShowSummary: import("@angular/core").WritableSignal<boolean>;
35
38
  formAppearance: import("@angular/core").WritableSignal<"outline" | "fill" | "simple">;
36
39
  formFloatLabel: import("@angular/core").WritableSignal<"auto" | "always">;
40
+ formAtLeastOneOfKeys: import("@angular/core").WritableSignal<string>;
41
+ formAtLeastOneOfMsg: import("@angular/core").WritableSignal<string>;
37
42
  formCode: import("@angular/core").WritableSignal<string>;
38
43
  currentId: import("@angular/core").WritableSignal<string | null>;
39
44
  showExport: import("@angular/core").WritableSignal<boolean>;
@@ -88,6 +93,21 @@ export declare class FormBuilderComponent {
88
93
  updateCondition(index: number, key: keyof FieldCondition, value: any): void;
89
94
  toggleUniqueCheck(enabled: boolean): void;
90
95
  setUniqueCheckProp(key: 'url' | 'message', value: string): void;
96
+ toggleLookup(enabled: boolean): void;
97
+ setLookupUrl(value: string): void;
98
+ setLookupMethod(value: string): void;
99
+ getLookupPopulateText(): string;
100
+ setLookupPopulateText(text: string): void;
101
+ getRequiredWhenConditions(): FieldCondition[];
102
+ addRequiredWhenCondition(): void;
103
+ removeRequiredWhenCondition(index: number): void;
104
+ updateRequiredWhenCondition(index: number, key: keyof FieldCondition, value: any): void;
105
+ updateCurrentStep(key: string, value: any): void;
106
+ getStepAtLeastOneOf(): string;
107
+ setStepAtLeastOneOf(text: string): void;
108
+ getStepBeforeNext(): StepGuard | undefined;
109
+ toggleBeforeNext(enabled: boolean): void;
110
+ setBeforeNextProp(key: keyof StepGuard, value: string): void;
91
111
  /** Presets de masques de saisie courants */
92
112
  readonly maskPresets: {
93
113
  label: string;
@@ -1,4 +1,5 @@
1
1
  import { EventEmitter, OnInit, OnChanges, SimpleChanges, ChangeDetectorRef } from '@angular/core';
2
+ import { HttpClient } from '@angular/common/http';
2
3
  import { FormGroup } from '@angular/forms';
3
4
  import { MatStepper } from '@angular/material/stepper';
4
5
  import { StepperFormConfig, DynamicFormSubmitEvent, DynamicFormField } from '../../models/form-field.model';
@@ -18,14 +19,25 @@ export declare class StepperFormComponent implements OnInit, OnChanges {
18
19
  private builder;
19
20
  private conditionEvaluator;
20
21
  private cdr;
22
+ private http;
21
23
  config: StepperFormConfig;
22
24
  initialValues?: Record<string, any>;
23
25
  formSubmit: EventEmitter<DynamicFormSubmitEvent>;
24
26
  formChange: EventEmitter<Record<string, any>>;
25
27
  stepChange: EventEmitter<number>;
28
+ /** Emitted on individual field value changes within any step */
29
+ fieldChange: EventEmitter<{
30
+ key: string;
31
+ value: any;
32
+ step: number;
33
+ }>;
34
+ /** Per-step loading state for the beforeNext guard */
35
+ guardLoading: Record<number, boolean>;
36
+ /** Per-step error message from the beforeNext guard */
37
+ guardError: Record<number, string | null>;
26
38
  stepper: MatStepper;
27
39
  stepForms: FormGroup[];
28
- constructor(builder: DynamicFormBuilderService, conditionEvaluator: ConditionEvaluatorService, cdr: ChangeDetectorRef);
40
+ constructor(builder: DynamicFormBuilderService, conditionEvaluator: ConditionEvaluatorService, cdr: ChangeDetectorRef, http: HttpClient);
29
41
  ngOnInit(): void;
30
42
  ngOnChanges(changes: SimpleChanges): void;
31
43
  private buildForms;
@@ -41,6 +53,6 @@ export declare class StepperFormComponent implements OnInit, OnChanges {
41
53
  getAllValues(): Record<string, any>;
42
54
  private getAllRawValues;
43
55
  static ɵfac: i0.ɵɵFactoryDeclaration<StepperFormComponent, never>;
44
- static ɵcmp: i0.ɵɵComponentDeclaration<StepperFormComponent, "ngx-stepper-form", never, { "config": { "alias": "config"; "required": true; }; "initialValues": { "alias": "initialValues"; "required": false; }; }, { "formSubmit": "formSubmit"; "formChange": "formChange"; "stepChange": "stepChange"; }, never, never, true, never>;
56
+ static ɵcmp: i0.ɵɵComponentDeclaration<StepperFormComponent, "ngx-stepper-form", never, { "config": { "alias": "config"; "required": true; }; "initialValues": { "alias": "initialValues"; "required": false; }; }, { "formSubmit": "formSubmit"; "formChange": "formChange"; "stepChange": "stepChange"; "fieldChange": "fieldChange"; }, never, never, true, never>;
45
57
  }
46
58
  export {};
@@ -6,6 +6,11 @@ export interface SelectOption {
6
6
  group?: string;
7
7
  dependsOnValue?: any;
8
8
  }
9
+ export interface FieldCondition {
10
+ field: string;
11
+ operator: 'equals' | 'notEquals' | 'contains' | 'greaterThan' | 'lessThan' | 'exists' | 'notExists';
12
+ value?: any;
13
+ }
9
14
  export interface FieldValidation {
10
15
  required?: boolean;
11
16
  minLength?: number;
@@ -15,6 +20,12 @@ export interface FieldValidation {
15
20
  pattern?: string | RegExp;
16
21
  email?: boolean;
17
22
  custom?: (value: any) => string | null;
23
+ /** Dynamically required when all (AND) / any (OR) conditions pass — uses field.conditionLogic */
24
+ requiredWhen?: FieldCondition | FieldCondition[];
25
+ /** This field's numeric value must be <= the value of the named sibling field */
26
+ maxField?: string;
27
+ /** This field's numeric value must be >= the value of the named sibling field */
28
+ minField?: string;
18
29
  messages?: {
19
30
  required?: string;
20
31
  minLength?: string;
@@ -23,12 +34,30 @@ export interface FieldValidation {
23
34
  max?: string;
24
35
  pattern?: string;
25
36
  email?: string;
37
+ maxField?: string;
38
+ minField?: string;
26
39
  };
27
40
  }
28
- export interface FieldCondition {
29
- field: string;
30
- operator: 'equals' | 'notEquals' | 'contains' | 'greaterThan' | 'lessThan' | 'exists' | 'notExists';
31
- value?: any;
41
+ /** Auto-populate sibling fields from an API call when this field loses focus */
42
+ export interface FieldLookup {
43
+ /** URL supporting {{fieldKey}} interpolation */
44
+ url: string;
45
+ method?: 'GET' | 'POST';
46
+ /** Map: targetSiblingFieldKey -> dotted.path.in.api.response */
47
+ populate: Record<string, string>;
48
+ /** @default 'blur' */
49
+ triggerOn?: 'blur' | 'change';
50
+ }
51
+ /** Async guard executed before advancing to the next stepper step */
52
+ export interface StepGuard {
53
+ url: string;
54
+ method?: 'GET' | 'POST';
55
+ /** Send all current step values as the request body */
56
+ withFormValues?: boolean;
57
+ /** If set, `Object.assign`-patches the next step's FormGroup with the entire API response object */
58
+ resultKey?: string;
59
+ /** Error message shown when the guard API call fails */
60
+ errorMessage?: string;
32
61
  }
33
62
  export interface DynamicFormField {
34
63
  key: string;
@@ -50,9 +79,12 @@ export interface DynamicFormField {
50
79
  dependsOnItemKey?: string;
51
80
  dependsOnOffset?: number;
52
81
  validation?: FieldValidation;
82
+ /** On blur: call lookup.url and patch sibling fields from the response */
83
+ lookup?: FieldLookup;
53
84
  col?: 1 | 2 | 3 | 4 | 6 | 8 | 9 | 12;
54
85
  cssClass?: string;
55
86
  showWhen?: FieldCondition | FieldCondition[];
87
+ conditionLogic?: 'AND' | 'OR';
56
88
  accept?: string;
57
89
  multiple?: boolean;
58
90
  rows?: number;
@@ -81,7 +113,6 @@ export interface DynamicFormField {
81
113
  fontWeight?: 'normal' | 'bold';
82
114
  fontStyle?: 'normal' | 'italic';
83
115
  styles?: Record<string, string>;
84
- conditionLogic?: 'AND' | 'OR';
85
116
  uniqueCheck?: {
86
117
  url: string;
87
118
  message?: string;
@@ -100,12 +131,22 @@ export interface DynamicFormConfig {
100
131
  debug?: boolean;
101
132
  appearance?: 'outline' | 'fill' | 'simple';
102
133
  floatLabel?: 'auto' | 'always';
134
+ /** At least one of these field keys must have a non-empty value for the form to be valid */
135
+ atLeastOneOf?: string[];
136
+ /** Custom error message when atLeastOneOf constraint is violated */
137
+ atLeastOneOfMessage?: string;
103
138
  }
104
139
  export interface FormStep {
105
140
  label: string;
106
141
  icon?: string;
107
142
  description?: string;
108
143
  fields: DynamicFormField[];
144
+ /** Async guard: called before advancing to the next step. Blocks advance on API error. */
145
+ beforeNext?: StepGuard;
146
+ /** At least one of these field keys in this step must have a non-empty value */
147
+ atLeastOneOf?: string[];
148
+ /** Custom error message when atLeastOneOf constraint is violated */
149
+ atLeastOneOfMessage?: string;
109
150
  }
110
151
  export interface StepperFormConfig {
111
152
  steps: FormStep[];
@@ -1,9 +1,9 @@
1
1
  import { FormGroup } from '@angular/forms';
2
- import { DynamicFormField } from '../models/form-field.model';
2
+ import { FieldCondition, DynamicFormField } from '../models/form-field.model';
3
3
  import * as i0 from "@angular/core";
4
4
  export declare class ConditionEvaluatorService {
5
5
  isVisible(field: DynamicFormField, form: FormGroup): boolean;
6
- private evaluate;
6
+ evaluate(condition: FieldCondition, form: FormGroup): boolean;
7
7
  static ɵfac: i0.ɵɵFactoryDeclaration<ConditionEvaluatorService, never>;
8
8
  static ɵprov: i0.ɵɵInjectableDeclaration<ConditionEvaluatorService>;
9
9
  }
@@ -4,8 +4,21 @@ import * as i0 from "@angular/core";
4
4
  export declare class DynamicFormBuilderService {
5
5
  private uniqueness;
6
6
  buildFormGroup(fields: DynamicFormField[]): FormGroup;
7
+ /** Build group-level validators for cross-field constraints */
8
+ buildGroupValidators(fields: DynamicFormField[], atLeastOneOf?: string[], atLeastOneOfMessage?: string): ValidatorFn[];
7
9
  buildValidators(validation?: FieldValidation): ValidatorFn[];
8
10
  getErrorMessage(control: AbstractControl, validation?: FieldValidation): string | null;
11
+ /**
12
+ * Cross-field bound validator: sets an error on `fieldKey` when:
13
+ * mode 'max': field value > other field value
14
+ * mode 'min': field value < other field value
15
+ *
16
+ * Error is set directly on the FormControl so the existing per-field
17
+ * error display in DynamicFieldComponent picks it up automatically.
18
+ */
19
+ private crossFieldBoundValidator;
20
+ /** Group-level validator: at least one of the listed field keys must have a non-empty value */
21
+ atLeastOneOfValidator(keys: string[], msg?: string): ValidatorFn;
9
22
  static ɵfac: i0.ɵɵFactoryDeclaration<DynamicFormBuilderService, never>;
10
23
  static ɵprov: i0.ɵɵInjectableDeclaration<DynamicFormBuilderService>;
11
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suntelecoms/ngx-dynamic-form",
3
- "version": "1.5.1",
3
+ "version": "1.6.1",
4
4
  "description": "Générateur de formulaires Angular dynamiques — SUNTELECOMS",
5
5
  "author": "Amadou Diallo <amadoumacbookpro38@gmail.com>",
6
6
  "license": "MIT",