@suntelecoms/ngx-dynamic-form 1.12.0 → 1.12.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.
package/README.md CHANGED
@@ -2448,6 +2448,9 @@ export type { StepGuard } // { url, method?, withFormValues?, resultKey?, e
2448
2448
 
2449
2449
  ## Changelog
2450
2450
 
2451
+ ### v1.12.1
2452
+ - **Correctif** (`select`, `multiselect`, `radio`) : une valeur reçue d'une API avec un autre type que les options (ex. booléen `true` pour une option `"true"`, nombre `1` pour `"1"` — le Form Builder enregistre les valeurs d'option en texte) est alignée sur l'option correspondante. Auparavant la liste restait vide en mode édition (comparaison stricte).
2453
+
2451
2454
  ### v1.12.0
2452
2455
  - **`file` + `upload`** : envoi immédiat de chaque fichier vers une API décrite par la config du champ (URL, méthode, en-têtes, parties multipart, lecture de la réponse, suppression, téléchargement). Progression, erreur du backend affichée telle quelle avec « Réessayer », champ invalide pendant l'envoi ; la valeur devient le document enregistré (objet ou id), sérialisable en JSON. Voir [Envoi de fichiers vers une API](#envoi-de-fichiers-vers-une-api--upload).
2453
2456
  - **`maxFileSize`** (octets) sur `file` : fichier refusé avant envoi, avec un message sous la zone de dépôt.
@@ -1480,6 +1480,37 @@ class DynamicFieldComponent {
1480
1480
  if (this.field?.type === 'multiselect' && this.field.display === 'cards' && this.form?.get(this.field.key)) {
1481
1481
  queueMicrotask(() => this.ensureLockedOptions());
1482
1482
  }
1483
+ if (this.form?.get(this.field?.key)) {
1484
+ queueMicrotask(() => this.alignValueOnOptions());
1485
+ }
1486
+ }
1487
+ /**
1488
+ * Valeur reçue d'une API (ex: booléen `true`, nombre `1`) alors que les options du formulaire portent
1489
+ * la même valeur en texte (`"true"`, `"1"` — le Form Builder enregistre les valeurs d'option en texte) :
1490
+ * la valeur prend celle de l'option correspondante, sinon la liste n'affiche rien (comparaison stricte).
1491
+ * Sans effet si la valeur correspond déjà à une option, est vide ou ne correspond à aucune.
1492
+ */
1493
+ alignValueOnOptions() {
1494
+ if (!['select', 'multiselect', 'radio'].includes(this.field?.type))
1495
+ return;
1496
+ const control = this.form?.get(this.field.key);
1497
+ const options = this._resolvedOptions;
1498
+ if (!control || !options?.length)
1499
+ return;
1500
+ const scalar = (v) => v != null && v !== '' && typeof v !== 'object';
1501
+ const align = (v) => {
1502
+ if (!scalar(v) || options.some(o => o.value === v))
1503
+ return v;
1504
+ const match = options.find(o => scalar(o.value) && String(o.value) === String(v));
1505
+ return match ? match.value : v;
1506
+ };
1507
+ const value = control.value;
1508
+ const next = Array.isArray(value) ? value.map(align) : align(value);
1509
+ const changed = Array.isArray(value) ? next.some((v, i) => v !== value[i]) : next !== value;
1510
+ if (changed) {
1511
+ control.setValue(next, { emitEvent: false });
1512
+ this.cdr.markForCheck();
1513
+ }
1483
1514
  }
1484
1515
  get remoteSearchHasEnoughChars() {
1485
1516
  const text = this.searchDisplayControl.value;
@@ -1894,6 +1925,11 @@ class DynamicFieldComponent {
1894
1925
  queueMicrotask(() => this.ensureLockedOptions());
1895
1926
  this.formControl.valueChanges.subscribe(() => this.ensureLockedOptions());
1896
1927
  }
1928
+ // Valeur posée après coup (patchValue, mode édition) : même alignement sur le type des options.
1929
+ if (this.hasOptions) {
1930
+ queueMicrotask(() => this.alignValueOnOptions());
1931
+ this.formControl.valueChanges.subscribe(() => this.alignValueOnOptions());
1932
+ }
1897
1933
  // Convertit une valeur string "YYYY-MM-DD" en Date pour le mat-datepicker
1898
1934
  if (this.field.type === 'date' && !this.isSimple) {
1899
1935
  this.dateAdapter.setLocale(this.field.dateLocale ?? this.globalDateLocale);