@suntelecoms/ngx-dynamic-form 1.6.5 → 1.6.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.
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  [![Angular](https://img.shields.io/badge/Angular-19-red?logo=angular)](https://angular.dev)
6
6
  [![Angular Material](https://img.shields.io/badge/Angular_Material-19-blue?logo=material-design)](https://material.angular.io)
7
- [![Version](https://img.shields.io/badge/version-1.6.0-brightgreen)](CHANGELOG.md)
7
+ [![Version](https://img.shields.io/badge/version-1.6.6-brightgreen)](CHANGELOG.md)
8
8
  [![License](https://img.shields.io/badge/License-MIT-green)](LICENSE)
9
9
  [![Author](https://img.shields.io/badge/Author-Amadou%20Diallo-purple)](mailto:amadoumacbookpro38@gmail.com)
10
10
 
@@ -247,7 +247,7 @@ Pour disposer du **Form Builder + gestionnaire + rendu par URL** dans votre appl
247
247
 
248
248
  | Type | Rendu | Description |
249
249
  |---|---|---|
250
- | `date` | `mat-datepicker` | Calendrier Material — popup avec sélection mois/année _(v1.2.8)_ |
250
+ | `date` | `mat-datepicker` | Calendrier Material — popup avec sélection mois/année _(v1.2.8)_ ; `minDate`/`maxDate` pour borner les dates sélectionnables, `'today'` ou une date ISO _(v1.6.6)_ |
251
251
  | `datetime-local` | `<input type="datetime-local">` | Date et heure combinées |
252
252
  | `time` | `<input type="time">` | Heure (HH:mm) |
253
253
  | `month` | `<input type="month">` | Mois et année |
@@ -376,6 +376,14 @@ interface DynamicFormField {
376
376
  // Spécifique textarea
377
377
  rows?: number; // Défaut : 3
378
378
 
379
+ // Spécifique date ← v1.6.6
380
+ minDate?: string; // 'today', ou une date ISO ('2026-01-01')
381
+ maxDate?: string; // idem — borne le mat-datepicker et l'input natif (apparence simple)
382
+ // Exemple — une date de mise en circulation ne peut pas être dans le futur :
383
+ // { key: 'dateMiseCirculation', type: 'date', label: 'Date de mise en circulation', maxDate: 'today' }
384
+ // Une date de rendez-vous ne peut pas être dans le passé :
385
+ // { key: 'dateRdv', type: 'date', label: 'Date du rendez-vous', minDate: 'today' }
386
+
379
387
  // Spécifique heading
380
388
  text?: string;
381
389
  level?: 1|2|3|4|5|6; // Défaut : 2
@@ -720,6 +728,9 @@ interface FieldValidation {
720
728
  requiredWhen?: string;
721
729
  maxField?: string;
722
730
  minField?: string;
731
+ // type: 'date' uniquement — affiché quand la date choisie est hors des bornes minDate/maxDate du champ ← v1.6.6
732
+ minDate?: string;
733
+ maxDate?: string;
723
734
  };
724
735
  }
725
736
  ```
@@ -2008,6 +2019,9 @@ export type { StepGuard } // { url, method?, withFormValues?, resultKey?, e
2008
2019
 
2009
2020
  ## Changelog
2010
2021
 
2022
+ ### v1.6.6
2023
+ - **Bornes de date `minDate` / `maxDate`** : propriétés sur `DynamicFormField` pour le type `date` — `'today'` (résolu dynamiquement à chaque rendu) ou une date ISO fixe (`'2026-01-01'`). Bornent le `mat-datepicker` (apparence `outline`/`fill`) et l'attribut natif `min`/`max` de l'`<input type="date">` (apparence `simple`). Message d'erreur dédié (`messages.minDate` / `messages.maxDate`) quand la date choisie sort de l'intervalle — auparavant ces cas remontaient un générique « Valeur invalide. »
2024
+
2011
2025
  ### v1.6.0
2012
2026
  - **Auto-remplissage `lookup`** : propriété `lookup: FieldLookup` sur `DynamicFormField` — à la perte de focus, requête GET ou POST vers `url` (interpolation `{{key}}`), remplissage des champs cibles via une map `populate` en notation pointée (`data.prenom`, etc.)
2013
2027
  - **Required conditionnel `requiredWhen`** : propriété `requiredWhen: FieldCondition | FieldCondition[]` dans `FieldValidation` — active `Validators.required` dynamiquement sans code impératif dans l'hôte ; réévalué à chaque changement du formulaire
@@ -141,6 +141,12 @@ class DynamicFormBuilderService {
141
141
  return msgs['max'] ?? `Valeur maximum : ${control.errors['max'].max}.`;
142
142
  if (control.errors['pattern'])
143
143
  return msgs['pattern'] ?? 'Format invalide.';
144
+ if (control.errors['matDatepickerMin'])
145
+ return (msgs['minDate'] ??
146
+ `La date doit être à partir du ${this.formatDateFr(control.errors['matDatepickerMin'].min)}.`);
147
+ if (control.errors['matDatepickerMax'])
148
+ return (msgs['maxDate'] ??
149
+ `La date doit être au plus tard le ${this.formatDateFr(control.errors['matDatepickerMax'].max)}.`);
144
150
  if (control.errors['custom'])
145
151
  return control.errors['custom'];
146
152
  if (control.errors['uniqueness'])
@@ -159,6 +165,9 @@ class DynamicFormBuilderService {
159
165
  : 'Au moins un des champs doit être renseigné.';
160
166
  return 'Valeur invalide.';
161
167
  }
168
+ formatDateFr(d) {
169
+ return d.toLocaleDateString('fr-FR');
170
+ }
162
171
  /**
163
172
  * Cross-field bound validator: sets an error on `fieldKey` when:
164
173
  * mode 'max': field value > other field value
@@ -1017,6 +1026,36 @@ class DynamicFieldComponent {
1017
1026
  return null;
1018
1027
  return this.builder.getErrorMessage(ctrl, this.field.validation);
1019
1028
  }
1029
+ /** field.minDate/maxDate ('today' or an ISO 'YYYY-MM-DD' string) resolved to a Date, for the mat-datepicker's [min]/[max]. */
1030
+ get minDate() {
1031
+ return this.resolveFieldDate(this.field.minDate);
1032
+ }
1033
+ get maxDate() {
1034
+ return this.resolveFieldDate(this.field.maxDate);
1035
+ }
1036
+ /** Same bound, as 'YYYY-MM-DD' for the native <input type="date"> min/max attributes (simple appearance). */
1037
+ get minDateAttr() {
1038
+ return this.toIsoDateString(this.minDate);
1039
+ }
1040
+ get maxDateAttr() {
1041
+ return this.toIsoDateString(this.maxDate);
1042
+ }
1043
+ resolveFieldDate(value) {
1044
+ if (!value)
1045
+ return undefined;
1046
+ if (value === 'today')
1047
+ return new Date();
1048
+ const d = new Date(value + 'T12:00:00');
1049
+ return isNaN(d.getTime()) ? undefined : d;
1050
+ }
1051
+ toIsoDateString(d) {
1052
+ if (!d)
1053
+ return undefined;
1054
+ const y = d.getFullYear();
1055
+ const m = String(d.getMonth() + 1).padStart(2, '0');
1056
+ const day = String(d.getDate()).padStart(2, '0');
1057
+ return `${y}-${m}-${day}`;
1058
+ }
1020
1059
  setupRequiredWhen() {
1021
1060
  const rw = this.field.validation.requiredWhen;
1022
1061
  const conditions = Array.isArray(rw) ? rw : [rw];
@@ -1238,7 +1277,7 @@ class DynamicFieldComponent {
1238
1277
  <input [id]="field.key" class="ngx-simple-input" type="date"
1239
1278
  [formControl]="formControl"
1240
1279
  [readonly]="field.readonly || false"
1241
- [attr.min]="field.validation?.min" [attr.max]="field.validation?.max" />
1280
+ [attr.min]="minDateAttr" [attr.max]="maxDateAttr" />
1242
1281
  </div>
1243
1282
  @if (field.hint && !hasError) { <small class="ngx-simple-hint">{{ field.hint }}</small> }
1244
1283
  @if (hasError) { <small class="ngx-simple-error-msg">{{ errorMessage }}</small> }
@@ -1250,7 +1289,8 @@ class DynamicFieldComponent {
1250
1289
  <input matInput [matDatepicker]="datepicker" [id]="field.key"
1251
1290
  [formControl]="formControl"
1252
1291
  [placeholder]="field.placeholder || ''"
1253
- [readonly]="field.readonly || false" />
1292
+ [readonly]="field.readonly || false"
1293
+ [min]="minDate" [max]="maxDate" />
1254
1294
  <mat-datepicker-toggle matIconSuffix [for]="datepicker" />
1255
1295
  <mat-datepicker #datepicker />
1256
1296
  @if (field.hint) { <mat-hint>{{ field.hint }}</mat-hint> }
@@ -1698,7 +1738,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
1698
1738
  <input [id]="field.key" class="ngx-simple-input" type="date"
1699
1739
  [formControl]="formControl"
1700
1740
  [readonly]="field.readonly || false"
1701
- [attr.min]="field.validation?.min" [attr.max]="field.validation?.max" />
1741
+ [attr.min]="minDateAttr" [attr.max]="maxDateAttr" />
1702
1742
  </div>
1703
1743
  @if (field.hint && !hasError) { <small class="ngx-simple-hint">{{ field.hint }}</small> }
1704
1744
  @if (hasError) { <small class="ngx-simple-error-msg">{{ errorMessage }}</small> }
@@ -1710,7 +1750,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
1710
1750
  <input matInput [matDatepicker]="datepicker" [id]="field.key"
1711
1751
  [formControl]="formControl"
1712
1752
  [placeholder]="field.placeholder || ''"
1713
- [readonly]="field.readonly || false" />
1753
+ [readonly]="field.readonly || false"
1754
+ [min]="minDate" [max]="maxDate" />
1714
1755
  <mat-datepicker-toggle matIconSuffix [for]="datepicker" />
1715
1756
  <mat-datepicker #datepicker />
1716
1757
  @if (field.hint) { <mat-hint>{{ field.hint }}</mat-hint> }