kwikid-forms 0.5.11 → 0.5.13

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.
@@ -856,6 +856,9 @@
856
856
  case "pattern":
857
857
  errorMessage = fieldLabel + " is in incorrect format!";
858
858
  break;
859
+ case "onlyWhitespaces":
860
+ errorMessage = fieldLabel + " can't contain only empty spaces!";
861
+ break;
859
862
  default:
860
863
  errorMessage = fieldLabel + ": " + errorType;
861
864
  break;
@@ -2698,6 +2701,7 @@
2698
2701
  (kwikidToolkit.checkObjectKeyExists(field, "validators") &&
2699
2702
  kwikidToolkit.checkObjectKeyExists(field.validators, "required") &&
2700
2703
  field.validators.required)) {
2704
+ validators.push(NoWhitespacesValidator());
2701
2705
  validators.push(i3.Validators.required);
2702
2706
  }
2703
2707
  if (kwikidToolkit.checkObjectKeyExists(field, "validators") &&
@@ -2722,6 +2726,10 @@
2722
2726
  }
2723
2727
  }
2724
2728
  }
2729
+ if (kwikidToolkit.checkObjectKeyExists(field, "validators") &&
2730
+ kwikidToolkit.checkObjectKeyExists(field.validators, "whitespace")) {
2731
+ validators.push(NoWhitespacesValidator());
2732
+ }
2725
2733
  return validators;
2726
2734
  };
2727
2735
  FormValidation.prototype.getFormFieldsValidationErrors = function (formGroup) {
@@ -2781,6 +2789,15 @@
2781
2789
  __decorate([
2782
2790
  kwikidToolkit.logMethod
2783
2791
  ], FormValidation.prototype, "getFormFieldsInvalidControls", null);
2792
+ function NoWhitespacesValidator() {
2793
+ return function (control) {
2794
+ var value = control.value;
2795
+ if (!value || typeof value !== "string") {
2796
+ return null;
2797
+ }
2798
+ return kwikidToolkit.hasWhitespacesOnly(value) ? { onlyWhitespaces: true } : null;
2799
+ };
2800
+ }
2784
2801
 
2785
2802
  var KwikIDFormViewService = /** @class */ (function () {
2786
2803
  function KwikIDFormViewService() {
@@ -4098,11 +4115,24 @@
4098
4115
  */
4099
4116
  KwikIDFormViewComponent.prototype.updateFiles = function (file, state, key) {
4100
4117
  var _h;
4118
+ var _a;
4101
4119
  var fileWithState = kwikidToolkit.mergeObjects(file, { state: state });
4102
- var updatedFiles = __spreadArray(__spreadArray([], __read(this.files[key].filter(function (f) { return f.name !== fileWithState.name || f.size !== fileWithState.size; }))), [
4103
- fileWithState
4104
- ]);
4105
- this.files[key] = filterDuplicatesFiles(updatedFiles);
4120
+ var field = getFormFieldByKey(this.formFields, key);
4121
+ if ((_a = field.properties) === null || _a === void 0 ? void 0 : _a.multiple) {
4122
+ // If field.properties?.multiple is true, it means multiple files are allowed for this field.
4123
+ // Update the existing files array for the specific key with the new file.
4124
+ var updatedFiles = __spreadArray(__spreadArray([], __read(this.files[key].filter(function (f) { return f.name !== fileWithState.name || f.size !== fileWithState.size; }))), [
4125
+ fileWithState
4126
+ ]);
4127
+ // Apply the filterDuplicatesFiles function to ensure uniqueness in the updatedFiles array.
4128
+ this.files[key] = filterDuplicatesFiles(updatedFiles);
4129
+ }
4130
+ else {
4131
+ // If field.properties?.multiple is false, only one file is allowed for this field.
4132
+ // Replace the existing files array for the specific key with an array containing the new file.
4133
+ this.files[key] = [fileWithState];
4134
+ }
4135
+ // Update the formData and formGroup controls for the specific key with the normalFiles array.
4106
4136
  var normalFiles = this.files[key].filter(function (file) {
4107
4137
  return file.state === "NORMAL";
4108
4138
  });