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

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) {
@@ -10593,6 +10598,8 @@ class PageBaseComponent {
10593
10598
  * @param event
10594
10599
  */
10595
10600
  async onSave(event) {
10601
+ // Show the saving overlay in case we have async validators in play
10602
+ this.showStatus(PageStatus.Saving);
10596
10603
  this.formGroup.markAllAsTouched();
10597
10604
  // If the form has pending async validators, wait for it them to complete before proceeding
10598
10605
  if (this.formGroup.pending) {
@@ -10602,6 +10609,8 @@ class PageBaseComponent {
10602
10609
  await this.save();
10603
10610
  }
10604
10611
  else {
10612
+ // Remove the saving overlay to display any errors
10613
+ this.showStatus(PageStatus.Loaded);
10605
10614
  // Only show the banner with the generic message if the parent component hasn't already set one
10606
10615
  // by implementing onSave for additional validation
10607
10616
  if (this.errors === '') {