@energycap/components 0.39.21-ECAP-25650-file-upload-validation-support.20240805-1706 → 0.39.21-ECAP-25650-file-upload-validation-support.20240806-0942

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.
@@ -4108,8 +4108,8 @@ class FileUploadComponent extends FormControlBase {
4108
4108
  // static class to create the form group from a parent component
4109
4109
  static getFormModel(validators, disabled = false, fileValidators) {
4110
4110
  let formGroup = new FormGroup({
4111
- file: new FormControl({ value: null, disabled: disabled }, validators),
4112
- name: new FormControl({ value: null, disabled: disabled }, { validators: validators, asyncValidators: fileValidators }),
4111
+ file: new FormControl({ value: null, disabled: disabled }, { validators: validators, asyncValidators: fileValidators }),
4112
+ name: new FormControl({ value: null, disabled: disabled }, validators),
4113
4113
  base64FileString: new FormControl(null),
4114
4114
  uploadResult: new FormControl(null),
4115
4115
  });
@@ -4119,10 +4119,10 @@ class FileUploadComponent extends FormControlBase {
4119
4119
  return formGroup;
4120
4120
  }
4121
4121
  static getFileValidator(callback) {
4122
- return async (nameControl) => {
4123
- if (nameControl.value && nameControl.parent && nameControl.parent.get('file')?.value) {
4124
- let file = nameControl.parent.get('file')?.value;
4125
- let base64 = nameControl.parent.get('base64FileString')?.value;
4122
+ return async (control) => {
4123
+ if (control.value && control.parent) {
4124
+ let file = control.value;
4125
+ let base64 = control.parent.get('base64FileString')?.value;
4126
4126
  return await callback(file, base64);
4127
4127
  }
4128
4128
  return null;
@@ -4173,6 +4173,11 @@ class FileUploadComponent extends FormControlBase {
4173
4173
  });
4174
4174
  }
4175
4175
  });
4176
+ // Sync errors from the file control to the name control whenever the file control status changes
4177
+ this.formModel.get('file')?.statusChanges.pipe(takeUntil(this.componentDestroyed)).subscribe(() => {
4178
+ const errors = this.formModel.get('file')?.errors ?? null;
4179
+ this.formModel.get('name')?.setErrors(errors);
4180
+ });
4176
4181
  }
4177
4182
  async fileChange(files) {
4178
4183
  if (this.multiSelect) {