@fovestta2/web-angular 1.1.1 → 1.1.5

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.
@@ -3314,8 +3314,48 @@ class AddUpdateFormComponent {
3314
3314
  }
3315
3315
  ngOnChanges(changes) {
3316
3316
  if (changes['config'] && !changes['config'].firstChange) {
3317
+ this.updateExistingForm();
3318
+ }
3319
+ }
3320
+ updateExistingForm() {
3321
+ if (!this.form) {
3317
3322
  this.initializeForm();
3323
+ return;
3318
3324
  }
3325
+ this.config.sections.forEach((section) => {
3326
+ if (!section.isRepeatable) {
3327
+ section.fields.forEach((column) => {
3328
+ const control = this.form.get(column.name);
3329
+ if (control) {
3330
+ const validators = this.buildValidators(column.validations, this.form);
3331
+ control.setValidators(validators);
3332
+ control.updateValueAndValidity({ emitEvent: false });
3333
+ const isDisabled = this.isFieldDisabled(column, this.form);
3334
+ if (isDisabled && control.enabled)
3335
+ control.disable({ emitEvent: false });
3336
+ else if (!isDisabled && control.disabled)
3337
+ control.enable({ emitEvent: false });
3338
+ }
3339
+ else {
3340
+ let initialValue = column.value || '';
3341
+ if (column.type === 'month-year' && initialValue)
3342
+ initialValue = this.formatMonthYearValue(initialValue);
3343
+ const newControl = this.fb.control({ value: initialValue, disabled: (typeof column.disabled === 'boolean' ? column.disabled : false) });
3344
+ const validators = this.buildValidators(column.validations, this.form);
3345
+ newControl.setValidators(validators);
3346
+ this.form.addControl(column.name, newControl);
3347
+ const subscription = newControl.valueChanges
3348
+ .pipe(distinctUntilChanged())
3349
+ .subscribe((value) => {
3350
+ const col = this.getColumnByName(column.name);
3351
+ if (col?.onChange)
3352
+ col.onChange(value, this.form);
3353
+ });
3354
+ this.valueChangeSubscriptions.push(subscription);
3355
+ }
3356
+ });
3357
+ }
3358
+ });
3319
3359
  }
3320
3360
  ngAfterViewInit() {
3321
3361
  // Lifecycle hook - can be used for datepicker initialization if needed