@eqproject/eqp-dynamic-module 2.10.83 → 2.10.85

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.
@@ -1188,10 +1188,22 @@ class UtilityHelperService {
1188
1188
  * In nuovo FormControl avrà il nome del campo passato e verranno impostati i Validators in base al tipo del campo stesso.
1189
1189
  * @param field BaseField per cui creare il FormControl da inserire nel FormGroup dela form.
1190
1190
  */
1191
+ /**
1192
+ * Validator "required" che legge dal record invece che da control.value.
1193
+ * Serve per far funzionare la validazione quando il valore viene impostato via formula/ActionButton
1194
+ * (che aggiornano record[fieldName] direttamente senza passare dal FormControl).
1195
+ */
1196
+ createRecordRequiredValidator(record, fieldName) {
1197
+ return () => {
1198
+ const v = record[fieldName];
1199
+ const isEmpty = v == null || ((typeof v === 'string' || Array.isArray(v)) && v.length === 0);
1200
+ return isEmpty ? { required: true } : null;
1201
+ };
1202
+ }
1191
1203
  createFieldFormControl(field, record) {
1192
1204
  const validators = [];
1193
1205
  if (field.Required)
1194
- validators.push(Validators.required);
1206
+ validators.push(this.createRecordRequiredValidator(record, field.Name));
1195
1207
  switch (field.FieldType) {
1196
1208
  case FieldTypeEnum["Campo di testo"]:
1197
1209
  if (field.MaxLenght) {
@@ -8293,15 +8305,12 @@ class AddFormRecordComponent {
8293
8305
  f.updateField();
8294
8306
  } });
8295
8307
  }
8296
- // Le formule aggiornano record[fieldName] direttamente, senza passare dal FormControl.
8297
- // Qui risincronizziamo tutti i FormControl dal record, altrimenti la validazione required
8298
- // non si aggiorna quando un campo viene valorizzato via formula o ActionButton.
8308
+ // I validator required leggono da record[field.Name] (closure su record), quindi basta
8309
+ // chiamare updateValueAndValidity per far rileggere il valore aggiornato dalla formula/ActionButton.
8310
+ // Non si usa setValue per evitare che writeValue sui ControlValueAccessor scateni eventi → loop.
8299
8311
  if (this.form?.Fields) {
8300
8312
  this.form.Fields.forEach(field => {
8301
- const ctrl = field.FormFormGroup?.get(field.Name);
8302
- if (ctrl != null) {
8303
- ctrl.setValue(this.record[field.Name], { emitEvent: false });
8304
- }
8313
+ field.FormFormGroup?.get(field.Name)?.updateValueAndValidity({ emitEvent: false });
8305
8314
  });
8306
8315
  }
8307
8316
  }