@eqproject/eqp-dynamic-module 2.10.84 → 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) {
@@ -8237,12 +8249,6 @@ class AddFormRecordComponent {
8237
8249
  this.FormScalarTypeEnum = FormScalarTypeEnum;
8238
8250
  this.FieldTypeEnum = FieldTypeEnum;
8239
8251
  this.visibleActionButtons = new Array();
8240
- //#region onRecordChange
8241
- /**
8242
- * Metodo invocato al cambio del valore di ogni proprietà dell'oggetto record.
8243
- * Serve ad aggiornare il valore di tutti i campi che hanno una formula.
8244
- */
8245
- this._isInRecordChange = false;
8246
8252
  }
8247
8253
  ngOnInit() {
8248
8254
  injectGoogleFontsFromForm(this.form);
@@ -8288,33 +8294,24 @@ class AddFormRecordComponent {
8288
8294
  GlobalService.speechDirective.SpeechToTextToggler();
8289
8295
  }
8290
8296
  }
8297
+ //#region onRecordChange
8298
+ /**
8299
+ * Metodo invocato al cambio del valore di ogni proprietà dell'oggetto record.
8300
+ * Serve ad aggiornare il valore di tutti i campi che hanno una formula.
8301
+ */
8291
8302
  onRecordChange() {
8292
- // Guardia di rientranza: setValue sui FormControl può triggerare writeValue sui ControlValueAccessor
8293
- // (es. mat-datepicker), che emettono (dateChange)/(ngModelChange) recordChange loop infinito.
8294
- if (this._isInRecordChange) {
8295
- return;
8296
- }
8297
- this._isInRecordChange = true;
8298
- try {
8299
- if (this.fieldTemplate && this.fieldTemplate.length > 0) {
8300
- this.fieldTemplate.forEach((f) => { if (f != null && typeof f.updateField === 'function') {
8301
- f.updateField();
8302
- } });
8303
- }
8304
- // Le formule aggiornano record[fieldName] direttamente, senza passare dal FormControl.
8305
- // Qui risincronizziamo i FormControl il cui valore è cambiato rispetto al record,
8306
- // altrimenti la validazione required fallisce sui campi valorizzati via formula/ActionButton.
8307
- if (this.form?.Fields) {
8308
- this.form.Fields.forEach(field => {
8309
- const ctrl = field.FormFormGroup?.get(field.Name);
8310
- if (ctrl != null && ctrl.value !== this.record[field.Name]) {
8311
- ctrl.setValue(this.record[field.Name], { emitEvent: false });
8312
- }
8313
- });
8314
- }
8303
+ if (this.fieldTemplate && this.fieldTemplate.length > 0) {
8304
+ this.fieldTemplate.forEach((f) => { if (f != null && typeof f.updateField === 'function') {
8305
+ f.updateField();
8306
+ } });
8315
8307
  }
8316
- finally {
8317
- this._isInRecordChange = false;
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.
8311
+ if (this.form?.Fields) {
8312
+ this.form.Fields.forEach(field => {
8313
+ field.FormFormGroup?.get(field.Name)?.updateValueAndValidity({ emitEvent: false });
8314
+ });
8318
8315
  }
8319
8316
  }
8320
8317
  //#endregion onRecordChange