@bnsights/bbsf-controls 1.0.179 → 1.0.180

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.
@@ -2122,7 +2122,6 @@ class FileUploadComponent {
2122
2122
  this.ERROR_DISPLAY_DURATION = 5000;
2123
2123
  this.MAX_MEMORY_USAGE = 100 * 1024 * 1024; // 100MB limit
2124
2124
  this.currentMemoryUsage = 0;
2125
- this.hasClearedRequiredError = false; // Track if required error was already cleared
2126
2125
  this.isSubmitted = false;
2127
2126
  this.OnChange = new EventEmitter();
2128
2127
  this.isUploadComplete = new EventEmitter();
@@ -2144,11 +2143,6 @@ class FileUploadComponent {
2144
2143
  this.removeRequiredValidation = () => {
2145
2144
  this.controlUtility.removeRequiredValidation(this.fileUploadFormControl, this.validationRules, this.options);
2146
2145
  };
2147
- this.removeRequiredValidatorOnly = () => {
2148
- this.validationRules = this.validationRules.filter(validator => validator !== Validators.required);
2149
- this.fileUploadFormControl.setValidators(this.validationRules);
2150
- this.fileUploadFormControl.updateValueAndValidity();
2151
- };
2152
2146
  this.addRequiredValidation = () => {
2153
2147
  this.controlUtility.addRequiredValidation(this.fileUploadFormControl, this.validationRules, this.options);
2154
2148
  };
@@ -2563,28 +2557,9 @@ class FileUploadComponent {
2563
2557
  }
2564
2558
  showFileCountError(errorKey, message) {
2565
2559
  const currentErrors = this.fileUploadFormControl.errors || {};
2566
- // Preserve existing errors and add the new one
2567
- const newErrors = { ...currentErrors };
2568
- newErrors[errorKey] = message;
2569
- this.fileUploadFormControl.setErrors(newErrors);
2560
+ currentErrors[errorKey] = message;
2561
+ this.fileUploadFormControl.setErrors(currentErrors);
2570
2562
  this.fileUploadFormControl.markAsTouched();
2571
- // Force the form control to be invalid
2572
- this.fileUploadFormControl.markAsDirty();
2573
- // Ensure the error persists
2574
- this.forceValidationErrorDisplay(errorKey, message);
2575
- }
2576
- forceValidationErrorDisplay(errorKey, message) {
2577
- // Force the validation error to persist by re-applying it after a short delay
2578
- setTimeout(() => {
2579
- const currentErrors = this.fileUploadFormControl.errors || {};
2580
- if (!currentErrors[errorKey]) {
2581
- const newErrors = { ...currentErrors };
2582
- newErrors[errorKey] = message;
2583
- this.fileUploadFormControl.setErrors(newErrors);
2584
- this.fileUploadFormControl.markAsTouched();
2585
- this.fileUploadFormControl.markAsDirty();
2586
- }
2587
- }, 100);
2588
2563
  }
2589
2564
  clearFileCountError(errorKey) {
2590
2565
  const currentErrors = this.fileUploadFormControl.errors;
@@ -2613,15 +2588,9 @@ class FileUploadComponent {
2613
2588
  const totalSizeMsg = this.utilityService.getResourceValue('TotalFileSizeExceeded')
2614
2589
  .replace('{maxSize}', this.options.maxSizeForAllFilesInMB.toString());
2615
2590
  const currentErrors = this.fileUploadFormControl.errors || {};
2616
- // Preserve existing errors and add the new one
2617
- const newErrors = { ...currentErrors };
2618
- newErrors['MaxSizeForAllFilesInMB'] = totalSizeMsg;
2619
- this.fileUploadFormControl.setErrors(newErrors);
2591
+ currentErrors['MaxSizeForAllFilesInMB'] = totalSizeMsg;
2592
+ this.fileUploadFormControl.setErrors(currentErrors);
2620
2593
  this.fileUploadFormControl.markAsTouched();
2621
- // Force the form control to be invalid
2622
- this.fileUploadFormControl.markAsDirty();
2623
- // Ensure the error persists
2624
- this.forceValidationErrorDisplay('MaxSizeForAllFilesInMB', totalSizeMsg);
2625
2594
  }
2626
2595
  validateFileSize(file) {
2627
2596
  const maxFileSize = this.options.fileMaxSizeInMB * this.BYTES_TO_MB;
@@ -2692,22 +2661,15 @@ class FileUploadComponent {
2692
2661
  return;
2693
2662
  const errorMessage = errors.join('<br/>');
2694
2663
  this.setValidationError('InvalidFiles', errorMessage);
2695
- // Increase the error display duration to prevent errors from disappearing too quickly
2696
2664
  setTimeout(() => {
2697
2665
  this.clearInvalidFilesError();
2698
- }, this.ERROR_DISPLAY_DURATION * 2); // Double the duration
2666
+ }, this.ERROR_DISPLAY_DURATION);
2699
2667
  }
2700
2668
  setValidationError(errorKey, errorMessage) {
2701
2669
  const currentErrors = this.fileUploadFormControl.errors || {};
2702
- // Preserve existing errors and add the new one
2703
- const newErrors = { ...currentErrors };
2704
- newErrors[errorKey] = errorMessage;
2705
- this.fileUploadFormControl.setErrors(newErrors);
2670
+ currentErrors[errorKey] = errorMessage;
2671
+ this.fileUploadFormControl.setErrors(currentErrors);
2706
2672
  this.fileUploadFormControl.markAsTouched();
2707
- // Force the form control to be invalid
2708
- this.fileUploadFormControl.markAsDirty();
2709
- // Ensure the error persists
2710
- this.forceValidationErrorDisplay(errorKey, errorMessage);
2711
2673
  }
2712
2674
  clearInvalidFilesError() {
2713
2675
  const currentErrors = this.fileUploadFormControl.errors;
@@ -2722,16 +2684,9 @@ class FileUploadComponent {
2722
2684
  }
2723
2685
  }
2724
2686
  setFormControlError(errorKey, errorValue) {
2725
- const currentErrors = this.fileUploadFormControl.errors || {};
2726
- // Preserve existing errors and add the new one
2727
- const newErrors = { ...currentErrors };
2728
- newErrors[errorKey] = errorValue;
2729
- this.fileUploadFormControl.setErrors(newErrors);
2687
+ this.fileUploadFormControl.setErrors({ [errorKey]: errorValue });
2730
2688
  this.fileUploadFormControl.markAsTouched();
2731
- this.fileUploadFormControl.markAsDirty();
2732
2689
  this.uploader.queue = [];
2733
- // Ensure the error persists
2734
- this.forceValidationErrorDisplay(errorKey, errorValue);
2735
2690
  }
2736
2691
  handleAsyncFileUpload(element, filesArray) {
2737
2692
  const uploadSubscription = this.fileUploadService.uploadFile(element._file).subscribe({
@@ -2874,30 +2829,11 @@ class FileUploadComponent {
2874
2829
  this.options.value = value;
2875
2830
  }
2876
2831
  preserveErrorsAndUpdateValue(value) {
2877
- // If we have a valid file value and haven't cleared the required error yet, remove it
2878
- if (this.hasValidFileValue(value) && !this.hasClearedRequiredError) {
2879
- // Use the custom method that only removes the validator without changing the isRequired option
2880
- // This keeps the asterisk visible while removing the validation logic
2881
- this.removeRequiredValidatorOnly();
2882
- // Mark that we've cleared the required error
2883
- this.hasClearedRequiredError = true;
2884
- }
2885
- // Set the form control value
2832
+ const currentErrors = this.fileUploadFormControl.errors;
2886
2833
  this.fileUploadFormControl.setValue(value, { emitEvent: false });
2887
- // Update the form group control value
2888
2834
  this.group.get(this.options.name)?.setValue(value, { emitEvent: false });
2889
- }
2890
- hasValidFileValue(value) {
2891
- if (!value)
2892
- return false;
2893
- if (this.options.isMultipleFile) {
2894
- const multipleValue = value;
2895
- return (multipleValue.uploadedFiles && multipleValue.uploadedFiles.length > 0) ||
2896
- (multipleValue.existingFiles && multipleValue.existingFiles.length > 0);
2897
- }
2898
- else {
2899
- const singleValue = value;
2900
- return singleValue.file && singleValue.file.fileName !== '';
2835
+ if (currentErrors) {
2836
+ this.fileUploadFormControl.setErrors(currentErrors);
2901
2837
  }
2902
2838
  }
2903
2839
  handlePatchAndEmit() {
@@ -2937,15 +2873,13 @@ class FileUploadComponent {
2937
2873
  this.fileUploadModel = null;
2938
2874
  if (this.options.isRequired) {
2939
2875
  this.fileUploadFormControl.markAsTouched();
2940
- // Use the existing utility function to add required validation back
2941
- this.addRequiredValidation();
2942
2876
  }
2943
- // Reset the flag so required validation can work again
2944
- this.hasClearedRequiredError = false;
2877
+ const currentErrors = this.fileUploadFormControl.errors;
2945
2878
  this.group.get(this.options.name)?.setValue(this.fileUploadModel, { emitEvent: false });
2879
+ if (currentErrors) {
2880
+ this.fileUploadFormControl.setErrors(currentErrors);
2881
+ }
2946
2882
  this.options.value = this.fileUploadModel;
2947
- // Re-evaluate all validations after file removal
2948
- this.reEvaluateAllValidations();
2949
2883
  }
2950
2884
  handleMultipleFileRemoval(item) {
2951
2885
  // Clean up blob URL
@@ -3011,97 +2945,17 @@ class FileUploadComponent {
3011
2945
  MinFileCountValidationKey: this.options.minNoOfFiles
3012
2946
  });
3013
2947
  this.fileUploadFormControl.markAsTouched();
3014
- this.addRequiredValidation();
3015
- this.hasClearedRequiredError = false;
3016
- }
3017
- // Re-evaluate all validations after file removal
3018
- this.reEvaluateAllValidations();
3019
- }
3020
- reEvaluateAllValidations() {
3021
- // Clear all existing validation errors first
3022
- this.fileUploadFormControl.setErrors(null);
3023
- // Re-apply required validation if needed
3024
- if (this.options.isRequired) {
3025
- this.addRequiredValidation();
3026
- }
3027
- // Re-validate file count constraints
3028
- this.reValidateFileCountConstraints();
3029
- // Re-validate total file size
3030
- this.reValidateTotalFileSize();
3031
- // Re-validate individual files
3032
- this.reValidateIndividualFiles();
3033
- // Clear validation errors that are no longer applicable
3034
- this.clearObsoleteValidationErrors();
3035
- // Update form control validity
3036
- this.fileUploadFormControl.updateValueAndValidity();
3037
- }
3038
- clearObsoleteValidationErrors() {
3039
- const currentFileCount = this.uploader.queue.length;
3040
- // Clear max file count error if current count is within limit
3041
- if (this.options.maxNoOfFiles > 0 && currentFileCount <= this.options.maxNoOfFiles) {
3042
- this.clearFileCountError('MaxFileCountValidationKey');
3043
- }
3044
- // Clear min file count error if current count meets minimum requirement
3045
- if (this.options.minNoOfFiles > 0 && currentFileCount >= this.options.minNoOfFiles) {
3046
- this.clearFileCountError('MinFileCountValidationKey');
3047
- }
3048
- // Clear total size error if current total size is within limit
3049
- if (this.options.maxSizeForAllFilesInMB > 0) {
3050
- const totalSize = this.uploader.queue.reduce((sum, element) => sum + element.file.size, 0);
3051
- const maxSizeBytes = this.options.maxSizeForAllFilesInMB * this.BYTES_TO_MB;
3052
- if (totalSize <= maxSizeBytes) {
3053
- this.clearFileCountError('MaxSizeForAllFilesInMB');
3054
- }
3055
- }
3056
- }
3057
- reValidateFileCountConstraints() {
3058
- const currentFileCount = this.uploader.queue.length;
3059
- // Check minimum file count
3060
- if (this.options.minNoOfFiles > 0 && currentFileCount < this.options.minNoOfFiles) {
3061
- const minFileMsg = this.utilityService.getResourceValue('MinimumFilesRequired')
3062
- .replace('{count}', this.options.minNoOfFiles.toString());
3063
- this.showFileCountError('MinFileCountValidationKey', minFileMsg);
3064
- }
3065
- // Check maximum file count
3066
- if (this.options.maxNoOfFiles > 0 && currentFileCount > this.options.maxNoOfFiles) {
3067
- const maxFileMsg = this.utilityService.getResourceValue('MaximumFilesExceeded') ||
3068
- `Maximum {maxCount} files allowed. You have selected {currentCount} files.`;
3069
- const finalMsg = maxFileMsg
3070
- .replace('{maxCount}', this.options.maxNoOfFiles.toString())
3071
- .replace('{currentCount}', currentFileCount.toString());
3072
- this.showFileCountError('MaxFileCountValidationKey', finalMsg);
3073
- }
3074
- }
3075
- reValidateTotalFileSize() {
3076
- if (this.options.maxSizeForAllFilesInMB > 0) {
3077
- const totalSize = this.uploader.queue.reduce((sum, element) => sum + element.file.size, 0);
3078
- const maxSizeBytes = this.options.maxSizeForAllFilesInMB * this.BYTES_TO_MB;
3079
- if (totalSize > maxSizeBytes) {
3080
- this.showTotalSizeError();
3081
- }
3082
- }
3083
- }
3084
- reValidateIndividualFiles() {
3085
- // Re-validate each remaining file for size and type
3086
- for (const element of this.uploader.queue) {
3087
- const file = element.file;
3088
- if (!file)
3089
- continue;
3090
- // Check file size
3091
- if (!this.validateIndividualFileSize(file)) {
3092
- this.setFormControlError('FileMaxSizeInMB', `${this.options.fileMaxSizeInMB}MB`);
3093
- }
3094
- // Check file type
3095
- if (!this.validateIndividualFileType(file)) {
3096
- this.setFormControlError('ToolTipTypeError', this.toolTipTypeArray);
3097
- }
3098
2948
  }
3099
2949
  }
3100
2950
  updateMultipleFileModel() {
3101
2951
  this.multipleFileUploadModel.correlationID_GUID = this.options.value?.correlationID_GUID;
2952
+ const currentErrors = this.fileUploadFormControl.errors;
3102
2953
  this.fileUploadFormControl.setValue(this.multipleFileUploadModel, { emitEvent: false });
3103
2954
  this.group.get(this.options.name)?.setValue(this.multipleFileUploadModel, { emitEvent: false });
3104
2955
  this.options.value = this.multipleFileUploadModel;
2956
+ if (currentErrors) {
2957
+ this.fileUploadFormControl.setErrors(currentErrors);
2958
+ }
3105
2959
  }
3106
2960
  convertSizeToMB(size) {
3107
2961
  if (size === 0) {