@everymatrix/general-input-hsl 0.25.42 → 0.25.43

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.
@@ -5790,6 +5790,13 @@ const DateInput = class {
5790
5790
  };
5791
5791
  DateInput.style = DateInputStyle0;
5792
5792
 
5793
+ function getFailedRegexRule(value, custom) {
5794
+ return (custom || []).find(rule => rule.rule === 'regex' && !new RegExp(rule.pattern).test(value));
5795
+ }
5796
+ function getRuleErrorMessage(rule, language) {
5797
+ return translate(rule.errorKey, language) || rule.errorMessage;
5798
+ }
5799
+
5793
5800
  const emailInputCss = "*,*::before,*::after{padding:0;margin:0;box-sizing:border-box}.email{font-family:\"Roboto\";font-style:normal}.email__wrapper{position:relative;width:100%}.email__wrapper--autofilled{pointer-events:none}.email__wrapper--autofilled .email__label{color:var(--emw--registration-typography, var(--emw--color-black, #000000))}.email__wrapper--autofilled .email__input{color:var(--emw--color-black, #000000)}.email__wrapper--flex{display:flex;gap:5px}.email__wrapper--relative{position:relative}.email__label{font-family:inherit;font-style:normal;font-weight:500;font-size:16px;line-height:20px;color:var(--emw--registration-typography, var(--emw--color-black, #000000))}.email__label--required::after{content:\"*\";font-family:inherit;color:var(--emw--login-color-primary, var(--emw--color-primary, #22B04E));margin-left:2px}.email__input{font-family:inherit;border-radius:4px;width:100%;height:40px;border:2px solid var(--emw--color-gray-100, #E6E6E6);color:var(--emw--color-black, #000000);border-radius:5px;box-sizing:border-box;font-size:16px;font-weight:300;line-height:1.5;padding:10px}.email__input:focus{outline-color:var(--emw--login-color-primary, var(--emw--color-primary, #22B04E))}.email__input--invalid{border:1px solid var(--emw--color-error, var(--emw--color-red, #ed0909))}.email__input::placeholder{color:var(--emw--color-gray-150, #828282)}.email__error-message{position:absolute;top:calc(100% + 5px);left:0;color:var(--emw--color-error, var(--emw--color-red, #ed0909))}.email__tooltip-icon{width:16px;height:auto}.email__tooltip{position:absolute;top:0;left:20px;background-color:var(--emw--color-white, #FFFFFF);border:1px solid var(--emw--color-gray-100, #E6E6E6);color:var(--emw--registration-typography, var(--emw--color-black, #000000));padding:10px;border-radius:5px;opacity:0;transition:opacity 0.3s ease-in-out;z-index:10}.email__tooltip.visible{opacity:1}";
5794
5801
  const EmailInputStyle0 = emailInputCss;
5795
5802
 
@@ -5798,7 +5805,6 @@ const EmailInput = class {
5798
5805
  registerInstance(this, hostRef);
5799
5806
  this.sendValidityState = createEvent(this, "sendValidityState", 7);
5800
5807
  this.sendInputValue = createEvent(this, "sendInputValue", 7);
5801
- this.validationPattern = '';
5802
5808
  this.touched = false;
5803
5809
  this.handleInput = (event) => {
5804
5810
  this.value = event.target.value;
@@ -5807,14 +5813,12 @@ const EmailInput = class {
5807
5813
  clearTimeout(this.debounceTime);
5808
5814
  }
5809
5815
  this.debounceTime = setTimeout(() => {
5810
- this.isValid = this.setValidity();
5811
- this.errorMessage = this.setErrorMessage();
5816
+ this.updateValidity();
5812
5817
  this.emitValueHandler(true);
5813
5818
  }, 500);
5814
5819
  };
5815
5820
  this.handleBlur = () => {
5816
- this.isValid = this.setValidity();
5817
- this.errorMessage = this.setErrorMessage();
5821
+ this.updateValidity();
5818
5822
  this.touched = true;
5819
5823
  };
5820
5824
  this.setClientStyling = () => {
@@ -5872,9 +5876,6 @@ const EmailInput = class {
5872
5876
  }
5873
5877
  }
5874
5878
  }
5875
- connectedCallback() {
5876
- this.validationPattern = this.setPattern();
5877
- }
5878
5879
  componentDidRender() {
5879
5880
  // start custom styling area
5880
5881
  if (!this.limitStylingAppends && this.stylingContainer) {
@@ -5885,39 +5886,39 @@ const EmailInput = class {
5885
5886
  // end custom styling area
5886
5887
  }
5887
5888
  componentDidLoad() {
5888
- this.isValid = this.setValidity();
5889
+ this.isValid = this.validate().isValid;
5889
5890
  if (this.defaultValue) {
5890
5891
  this.value = this.defaultValue;
5891
5892
  this.valueHandler({ name: this.name, value: this.value });
5892
5893
  }
5893
5894
  }
5894
- setValidity() {
5895
- return this.inputReference.validity.valid;
5895
+ updateValidity() {
5896
+ const { isValid, errorMessage } = this.validate();
5897
+ this.isValid = isValid;
5898
+ this.errorMessage = errorMessage;
5896
5899
  }
5897
- setPattern() {
5900
+ validate() {
5898
5901
  var _a, _b;
5899
- if (((_a = this.validation.custom) === null || _a === void 0 ? void 0 : _a.length) > 0) {
5900
- return (_b = this.validation.custom.find(customValidation => customValidation.rule === 'regex')) === null || _b === void 0 ? void 0 : _b.pattern;
5902
+ if (!this.inputReference) {
5903
+ return { isValid: false, errorMessage: '' };
5901
5904
  }
5902
- }
5903
- setErrorMessage() {
5904
- var _a, _b, _c, _d;
5905
5905
  if (this.inputReference.validity.valueMissing) {
5906
- return translate('requiredError', this.language);
5906
+ return { isValid: false, errorMessage: translate('requiredError', this.language) };
5907
5907
  }
5908
5908
  if (this.inputReference.validity.tooShort || this.inputReference.validity.tooLong) {
5909
- return translate('lengthError', this.language, { values: { minLength: this.validation.minLength, maxLength: this.validation.maxLength } });
5909
+ return { isValid: false, errorMessage: translate('lengthError', this.language, { values: { minLength: this.validation.minLength, maxLength: this.validation.maxLength } }) };
5910
5910
  }
5911
- if (this.inputReference.validity.patternMismatch) {
5912
- const errorCode = (_a = this.validation.custom.find(customValidation => customValidation.rule === 'regex')) === null || _a === void 0 ? void 0 : _a.errorKey;
5913
- const errorMessage = (_b = this.validation.custom.find(customValidation => customValidation.rule === 'regex')) === null || _b === void 0 ? void 0 : _b.errorMessage;
5914
- return translate(`${errorCode}`, this.language) ? translate(`${errorCode}`, this.language) : errorMessage;
5911
+ const inputValue = this.inputReference.value;
5912
+ const failedRegexRule = inputValue ? getFailedRegexRule(inputValue, this.validation.custom) : undefined;
5913
+ if (failedRegexRule) {
5914
+ return { isValid: false, errorMessage: getRuleErrorMessage(failedRegexRule, this.language) };
5915
5915
  }
5916
5916
  if (this.isDuplicateInput && this.duplicateInputValue !== this.value) {
5917
- const errorCode = (_c = this.validation.custom.find(customRule => customRule.rule === 'duplicate-input')) === null || _c === void 0 ? void 0 : _c.errorKey;
5918
- const errorMessage = (_d = this.validation.custom.find(customRule => customRule.rule === 'duplicate-input')) === null || _d === void 0 ? void 0 : _d.errorMessage;
5919
- return translate(`${errorCode}`, this.language) ? translate(`${errorCode}`, this.language) : errorMessage;
5917
+ const errorCode = (_a = this.validation.custom.find(customRule => customRule.rule === 'duplicate-input')) === null || _a === void 0 ? void 0 : _a.errorKey;
5918
+ const errorMessage = (_b = this.validation.custom.find(customRule => customRule.rule === 'duplicate-input')) === null || _b === void 0 ? void 0 : _b.errorMessage;
5919
+ return { isValid: false, errorMessage: translate(`${errorCode}`, this.language) ? translate(`${errorCode}`, this.language) : errorMessage };
5920
5920
  }
5921
+ return { isValid: this.inputReference.validity.valid, errorMessage: '' };
5921
5922
  }
5922
5923
  renderTooltip() {
5923
5924
  if (this.showTooltip) {
@@ -5930,8 +5931,8 @@ const EmailInput = class {
5930
5931
  if (this.touched) {
5931
5932
  invalidClass = this.isValid == true || this.isValid == undefined ? '' : 'text__input--invalid';
5932
5933
  }
5933
- return h("div", { key: '45255f597fcc76fa5e99601d7c2dd59afca32dbe', class: `email__wrapper ${this.autofilled ? 'number__wrapper--autofilled' : ''} ${this.name}__input`, ref: el => this.stylingContainer = el }, h("div", { key: '7e41609760d4cc0b5acb554749fce42e6bc88ef3', class: 'email__wrapper--flex' }, h("label", { key: '250a1656d714e8cbc943d153aa216a6322322534', class: `email__label ${this.validation.mandatory ? 'email__label--required' : ''}`, htmlFor: `${this.name}__input` }, this.displayName), h("div", { key: '80db5747730aaac2c1d0efa3129dfa5463fe779c', class: 'email__wrapper--relative' }, this.tooltip &&
5934
- h("img", { key: 'f10990c70bb3de310d137fa120575ad3582adbd3', class: 'email__tooltip-icon', src: tooltipIconSvg, alt: "", ref: (el) => this.tooltipIconReference = el, onClick: () => this.showTooltip = !this.showTooltip }), this.renderTooltip())), h("input", { key: '9cf1a9fc4fdc3cb2604c6ad21573091cc1b173aa', id: `${this.name}__input`, type: 'email', class: `email__input ${invalidClass}`, value: this.defaultValue, readOnly: this.autofilled, placeholder: `${this.placeholder}`, ref: (el) => this.inputReference = el, pattern: this.validationPattern, required: this.validation.mandatory, minlength: this.validation.minLength, maxlength: this.validation.maxLength, onInput: this.handleInput, onBlur: this.handleBlur }), h("small", { key: '1610834f1705f70bd1f2d4b0a6c37af3307cf77f', class: 'email__error-message' }, this.errorMessage));
5934
+ return h("div", { key: 'ff5657194151b872247fd966bc8dc7ab53f715de', class: `email__wrapper ${this.autofilled ? 'number__wrapper--autofilled' : ''} ${this.name}__input`, ref: el => this.stylingContainer = el }, h("div", { key: '8dc84da8787a50232fda2c113cf838598525a550', class: 'email__wrapper--flex' }, h("label", { key: 'b42e56122de79d841d99e183c6ed818a74c22020', class: `email__label ${this.validation.mandatory ? 'email__label--required' : ''}`, htmlFor: `${this.name}__input` }, this.displayName), h("div", { key: '7f09b2b675b28eebcd1e913b0cbdd43feb83b567', class: 'email__wrapper--relative' }, this.tooltip &&
5935
+ h("img", { key: '64c6c3565b60480d279a434f87efa36625da934b', class: 'email__tooltip-icon', src: tooltipIconSvg, alt: "", ref: (el) => this.tooltipIconReference = el, onClick: () => this.showTooltip = !this.showTooltip }), this.renderTooltip())), h("input", { key: '754ba4160c2633444064d334f451d0700815e8fc', id: `${this.name}__input`, type: 'email', class: `email__input ${invalidClass}`, value: this.defaultValue, readOnly: this.autofilled, placeholder: `${this.placeholder}`, ref: (el) => this.inputReference = el, required: this.validation.mandatory, minlength: this.validation.minLength, maxlength: this.validation.maxLength, onInput: this.handleInput, onBlur: this.handleBlur }), h("small", { key: '2d72cdde55c1a6b041bb37a1b5a2f3e1c17b558a', class: 'email__error-message' }, this.errorMessage));
5935
5936
  }
5936
5937
  static get watchers() { return {
5937
5938
  "clientStyling": ["handleStylingChange"],
@@ -5949,7 +5950,6 @@ const NumberInput = class {
5949
5950
  registerInstance(this, hostRef);
5950
5951
  this.sendValidityState = createEvent(this, "sendValidityState", 7);
5951
5952
  this.sendInputValue = createEvent(this, "sendInputValue", 7);
5952
- this.validationPattern = '';
5953
5953
  this.touched = false;
5954
5954
  this.handleInput = (event) => {
5955
5955
  this.value = event.target.value;
@@ -5958,14 +5958,12 @@ const NumberInput = class {
5958
5958
  clearTimeout(this.debounceTime);
5959
5959
  }
5960
5960
  this.debounceTime = setTimeout(() => {
5961
- this.isValid = this.setValidity();
5962
- this.errorMessage = this.setErrorMessage();
5961
+ this.updateValidity();
5963
5962
  this.emitValueHandler(true);
5964
5963
  }, 500);
5965
5964
  };
5966
5965
  this.handleBlur = () => {
5967
- this.isValid = this.setValidity();
5968
- this.errorMessage = this.setErrorMessage();
5966
+ this.updateValidity();
5969
5967
  this.touched = true;
5970
5968
  };
5971
5969
  this.setClientStyling = () => {
@@ -6015,9 +6013,6 @@ const NumberInput = class {
6015
6013
  this.showTooltip = false;
6016
6014
  }
6017
6015
  }
6018
- connectedCallback() {
6019
- this.validationPattern = this.setPattern();
6020
- }
6021
6016
  componentDidRender() {
6022
6017
  // start custom styling area
6023
6018
  if (!this.limitStylingAppends && this.stylingContainer) {
@@ -6028,34 +6023,33 @@ const NumberInput = class {
6028
6023
  // end custom styling area
6029
6024
  }
6030
6025
  componentDidLoad() {
6031
- this.isValid = this.setValidity();
6026
+ this.isValid = this.validate().isValid;
6032
6027
  if (this.defaultValue) {
6033
6028
  this.value = this.defaultValue;
6034
6029
  this.valueHandler({ name: this.name, value: this.value });
6035
6030
  }
6036
6031
  }
6037
- setValidity() {
6038
- return this.inputReference.validity.valid;
6032
+ updateValidity() {
6033
+ const { isValid, errorMessage } = this.validate();
6034
+ this.isValid = isValid;
6035
+ this.errorMessage = errorMessage;
6039
6036
  }
6040
- setPattern() {
6041
- var _a, _b;
6042
- if (((_a = this.validation.custom) === null || _a === void 0 ? void 0 : _a.length) > 0) {
6043
- return (_b = this.validation.custom.find(customValidation => customValidation.rule === 'regex')) === null || _b === void 0 ? void 0 : _b.pattern;
6037
+ validate() {
6038
+ if (!this.inputReference) {
6039
+ return { isValid: false, errorMessage: '' };
6044
6040
  }
6045
- }
6046
- setErrorMessage() {
6047
- var _a, _b;
6048
6041
  if (this.inputReference.validity.valueMissing) {
6049
- return translate('requiredError', this.language);
6042
+ return { isValid: false, errorMessage: translate('requiredError', this.language) };
6050
6043
  }
6051
6044
  if (this.inputReference.validity.rangeUnderflow || this.inputReference.validity.rangeOverflow) {
6052
- return translate('numberLengthError', this.language, { values: { min: this.validation.min, max: this.validation.max } });
6045
+ return { isValid: false, errorMessage: translate('numberLengthError', this.language, { values: { min: this.validation.min, max: this.validation.max } }) };
6053
6046
  }
6054
- if (this.inputReference.validity.patternMismatch) {
6055
- const errorCode = (_a = this.validation.custom.find(customValidation => customValidation.rule === 'regex')) === null || _a === void 0 ? void 0 : _a.errorKey;
6056
- const errorMessage = (_b = this.validation.custom.find(customValidation => customValidation.rule === 'regex')) === null || _b === void 0 ? void 0 : _b.errorMessage;
6057
- return translate(`${errorCode}`, this.language) ? translate(`${errorCode}`, this.language) : errorMessage;
6047
+ const value = this.inputReference.value;
6048
+ const failedRule = value ? getFailedRegexRule(value, this.validation.custom) : undefined;
6049
+ if (failedRule) {
6050
+ return { isValid: false, errorMessage: getRuleErrorMessage(failedRule, this.language) };
6058
6051
  }
6052
+ return { isValid: this.inputReference.validity.valid, errorMessage: '' };
6059
6053
  }
6060
6054
  renderTooltip() {
6061
6055
  if (this.showTooltip) {
@@ -6068,8 +6062,8 @@ const NumberInput = class {
6068
6062
  if (this.touched) {
6069
6063
  invalidClass = this.isValid == true || this.isValid == undefined ? '' : 'text__input--invalid';
6070
6064
  }
6071
- return h("div", { key: 'f0e6e6edb5d8e3f509474ef5536cb7ef717a5ee9', class: `number__wrapper ${this.autofilled ? 'number__wrapper--autofilled' : ''} ${this.name}__input`, ref: el => this.stylingContainer = el }, h("div", { key: 'c991d1e6ed0f9910104b46105daad5332200ee21', class: 'number__wrapper--flex' }, h("label", { key: 'd6912229dac4712f4f8e77a90f7ba0ebb7dd5548', class: `number__label ${this.validation.mandatory ? 'number__label--required' : ''}`, htmlFor: `${this.name}__input` }, this.displayName), h("div", { key: '5733806c60cad364e61fc66e25f89a44159e8ad9', class: 'number__wrapper--relative' }, this.tooltip &&
6072
- h("img", { key: '7ba9ca8048d04c41f800fccf03297e2db9a9115d', class: 'number__tooltip-icon', src: tooltipIconSvg, alt: "", ref: (el) => this.tooltipIconReference = el, onClick: () => this.showTooltip = !this.showTooltip }), this.renderTooltip())), h("input", { key: '4c4726f1ac0f3b3495ba6309f5fe4110b1ea5353', ref: (el) => this.inputReference = el, type: "number", inputMode: "numeric", value: this.defaultValue, readOnly: this.autofilled, id: `${this.name}__input`, class: `number__input ${invalidClass}`, pattern: this.validationPattern, placeholder: `${this.placeholder}`, required: this.validation.mandatory, max: this.validation.max, min: this.validation.min, onInput: this.handleInput, onBlur: this.handleBlur }), h("small", { key: '5217c1b0b4f4d9f741b5cdf6b7c3f01ef61fe180', class: 'number__error-message' }, this.errorMessage));
6065
+ return h("div", { key: 'edc8799baa52418673dcfccb82b1ff9d86159787', class: `number__wrapper ${this.autofilled ? 'number__wrapper--autofilled' : ''} ${this.name}__input`, ref: el => this.stylingContainer = el }, h("div", { key: '9d6313a06ff4fcd1174879745d48d37ac63c64a5', class: 'number__wrapper--flex' }, h("label", { key: '404af2d79da04a3156ebce45aae6d06ea21b5dc1', class: `number__label ${this.validation.mandatory ? 'number__label--required' : ''}`, htmlFor: `${this.name}__input` }, this.displayName), h("div", { key: '349120e9587af42941de2fd2405dc0b9b763372f', class: 'number__wrapper--relative' }, this.tooltip &&
6066
+ h("img", { key: '652d145a6a794f0e8370641d3f7fb28099603d62', class: 'number__tooltip-icon', src: tooltipIconSvg, alt: "", ref: (el) => this.tooltipIconReference = el, onClick: () => this.showTooltip = !this.showTooltip }), this.renderTooltip())), h("input", { key: 'e7908fe81f8afda735750cfe2bb7ac50d452c210', ref: (el) => this.inputReference = el, type: "number", inputMode: "numeric", value: this.defaultValue, readOnly: this.autofilled, id: `${this.name}__input`, class: `number__input ${invalidClass}`, placeholder: `${this.placeholder}`, required: this.validation.mandatory, max: this.validation.max, min: this.validation.min, onInput: this.handleInput, onBlur: this.handleBlur }), h("small", { key: '87e3e5afb6c790f9c57d79bdf0e12a897b10d799', class: 'number__error-message' }, this.errorMessage));
6073
6067
  }
6074
6068
  static get watchers() { return {
6075
6069
  "clientStyling": ["handleStylingChange"],
@@ -6090,7 +6084,6 @@ const PasswordInput = class {
6090
6084
  this.sendInputValue = createEvent(this, "sendInputValue", 7);
6091
6085
  this.touched = false;
6092
6086
  this.originalValid = false;
6093
- this.validationPattern = '';
6094
6087
  this.duplicateInputValue = null;
6095
6088
  this.handleInput = (event) => {
6096
6089
  this.value = event.target.value;
@@ -6101,8 +6094,7 @@ const PasswordInput = class {
6101
6094
  clearTimeout(this.debounceTime);
6102
6095
  }
6103
6096
  this.debounceTime = setTimeout(() => {
6104
- this.isValid = this.setValidity();
6105
- this.errorMessage = this.setErrorMessage();
6097
+ this.updateValidity();
6106
6098
  this.emitValueHandler(true);
6107
6099
  }, 500);
6108
6100
  };
@@ -6114,8 +6106,7 @@ const PasswordInput = class {
6114
6106
  this.value = event.target.value;
6115
6107
  this.showPopup = false;
6116
6108
  this.touched = true;
6117
- this.isValid = this.setValidity();
6118
- this.errorMessage = this.setErrorMessage();
6109
+ this.updateValidity();
6119
6110
  };
6120
6111
  this.handleFocus = () => {
6121
6112
  this.showPopup = true;
@@ -6160,7 +6151,7 @@ const PasswordInput = class {
6160
6151
  if (!this.isDuplicateInput) {
6161
6152
  // recalculate complexity immediately in order to send the correct validity to the duplicate
6162
6153
  this.calculateComplexity(this.value);
6163
- this.sendOriginalValidityState.emit({ name: this.name, valid: this.setValidity() });
6154
+ this.sendOriginalValidityState.emit({ name: this.name, valid: this.validate().isValid });
6164
6155
  }
6165
6156
  }
6166
6157
  emitValueHandler(newValue) {
@@ -6178,13 +6169,13 @@ const PasswordInput = class {
6178
6169
  if (this.isDuplicateInput) {
6179
6170
  if (event.detail.valid) {
6180
6171
  this.originalValid = true;
6181
- this.isValid = this.setValidity();
6172
+ this.isValid = this.validate().isValid;
6182
6173
  }
6183
6174
  else {
6184
6175
  this.originalValid = false;
6185
6176
  this.isValid = false;
6186
6177
  // only show error if the user has touched the input, in order to not show errors on empty inputs
6187
- this.value !== '' && (this.errorMessage = this.setErrorMessage());
6178
+ this.value !== '' && (this.errorMessage = this.validate().errorMessage);
6188
6179
  }
6189
6180
  }
6190
6181
  }
@@ -6192,15 +6183,13 @@ const PasswordInput = class {
6192
6183
  if (this.isDuplicateInput && this.name === event.detail.name + 'Duplicate') {
6193
6184
  this.duplicateInputValue = event.detail.value;
6194
6185
  if (this.touched) {
6195
- this.isValid = this.setValidity();
6196
- this.errorMessage = this.setErrorMessage();
6186
+ this.updateValidity();
6197
6187
  }
6198
6188
  }
6199
6189
  if (this.name === event.detail.name + 'Duplicate'
6200
6190
  && this.name.replace('Duplicate', '') === event.detail.name
6201
6191
  && this.touched === true) {
6202
- this.isValid = this.setValidity();
6203
- this.errorMessage = this.setErrorMessage();
6192
+ this.updateValidity();
6204
6193
  }
6205
6194
  }
6206
6195
  handleClickOutside(event) {
@@ -6234,7 +6223,7 @@ const PasswordInput = class {
6234
6223
  this.touched = true;
6235
6224
  }
6236
6225
  }
6237
- this.isValid = this.setValidity();
6226
+ this.isValid = this.validate().isValid;
6238
6227
  }
6239
6228
  disconnectedCallback() {
6240
6229
  this.passwordButton.removeEventListener('click', this.handleRevealField);
@@ -6248,48 +6237,36 @@ const PasswordInput = class {
6248
6237
  return { rule: rule.displayName, ruleKey: rule.errorKey, passed };
6249
6238
  });
6250
6239
  }
6251
- setValidity() {
6252
- var _a, _b;
6253
- if (this.isDuplicateInput && this.duplicateInputValue !== this.value) {
6254
- return false;
6255
- }
6256
- else if (!((_a = this.passwordComplexity) === null || _a === void 0 ? void 0 : _a.every(complexity => complexity.passed))) {
6257
- return false;
6258
- }
6259
- else {
6260
- return (_b = this.inputReference) === null || _b === void 0 ? void 0 : _b.validity.valid;
6261
- }
6262
- }
6263
- setPattern() {
6240
+ validate() {
6264
6241
  var _a, _b;
6265
- if (((_a = this.validation.custom) === null || _a === void 0 ? void 0 : _a.length) > 0) {
6266
- return (_b = this.validation.custom.find(customValidation => customValidation.rule === 'regex')) === null || _b === void 0 ? void 0 : _b.pattern;
6242
+ if (!this.inputReference) {
6243
+ return { isValid: false, errorMessage: '' };
6267
6244
  }
6268
- }
6269
- setErrorMessage() {
6270
- var _a, _b, _c, _d, _e;
6271
- if (this.inputReference.validity.tooShort || this.inputReference.validity.tooLong) {
6272
- return translate('lengthError', this.language, { values: { minLength: this.validation.minLength, maxLength: this.validation.maxLength } });
6245
+ const validity = this.inputReference.validity;
6246
+ const duplicateMismatch = this.isDuplicateInput && this.duplicateInputValue !== this.value;
6247
+ const complexityPassed = !!((_a = this.passwordComplexity) === null || _a === void 0 ? void 0 : _a.every(complexity => complexity.passed));
6248
+ if (validity.tooShort || validity.tooLong) {
6249
+ return { isValid: false, errorMessage: translate('lengthError', this.language, { values: { minLength: this.validation.minLength, maxLength: this.validation.maxLength } }) };
6273
6250
  }
6274
- if (this.inputReference.validity.valueMissing) {
6275
- return translate('requiredError', this.language);
6251
+ if (validity.valueMissing) {
6252
+ return { isValid: false, errorMessage: translate('requiredError', this.language) };
6276
6253
  }
6277
6254
  if (this.isDuplicateInput && !this.originalValid) {
6278
- return translate('invalidOriginalPasswordError', this.language);
6279
- }
6280
- if (this.inputReference.validity.patternMismatch) {
6281
- const errorCode = (_a = this.validation.custom.find(customValidation => customValidation.rule === 'regex')) === null || _a === void 0 ? void 0 : _a.errorKey;
6282
- const errorMessage = (_b = this.validation.custom.find(customValidation => customValidation.rule === 'regex')) === null || _b === void 0 ? void 0 : _b.errorMessage;
6283
- return translate(`${errorCode}`, this.language) ? translate(`${errorCode}`, this.language) : errorMessage;
6255
+ return { isValid: false, errorMessage: translate('invalidOriginalPasswordError', this.language) };
6284
6256
  }
6285
- if (this.isDuplicateInput && this.duplicateInputValue !== this.value) {
6286
- const errorCode = (_c = this.validation.custom.find(customRule => customRule.rule === 'duplicate-input')) === null || _c === void 0 ? void 0 : _c.errorKey;
6287
- const errorMessage = (_d = this.validation.custom.find(customRule => customRule.rule === 'duplicate-input')) === null || _d === void 0 ? void 0 : _d.errorMessage;
6288
- return translate(`${errorCode}`, this.language) ? translate(`${errorCode}`, this.language) : errorMessage;
6257
+ if (duplicateMismatch) {
6258
+ const duplicateRule = (_b = this.validation.custom) === null || _b === void 0 ? void 0 : _b.find(customRule => customRule.rule === 'duplicate-input');
6259
+ return { isValid: false, errorMessage: duplicateRule ? getRuleErrorMessage(duplicateRule, this.language) : '' };
6289
6260
  }
6290
- if (!((_e = this.passwordComplexity) === null || _e === void 0 ? void 0 : _e.every(complexity => complexity.passed)) && !this.showPopup) {
6291
- return translate('invalidPassword', this.language);
6261
+ if (!complexityPassed) {
6262
+ return { isValid: false, errorMessage: this.showPopup ? '' : translate('invalidPassword', this.language) };
6292
6263
  }
6264
+ return { isValid: validity.valid, errorMessage: '' };
6265
+ }
6266
+ updateValidity() {
6267
+ const { isValid, errorMessage } = this.validate();
6268
+ this.isValid = isValid;
6269
+ this.errorMessage = errorMessage;
6293
6270
  }
6294
6271
  renderTooltip() {
6295
6272
  if (this.showTooltip) {
@@ -6311,8 +6288,8 @@ const PasswordInput = class {
6311
6288
  if (this.touched) {
6312
6289
  invalidClass = this.isValid == true || this.isValid == undefined ? '' : 'text__input--invalid';
6313
6290
  }
6314
- return h("div", { key: 'e6a288d18a095de747c7eec28bcf117e5069cbc1', class: `password__wrapper ${this.autofilled ? 'password__wrapper--autofilled' : ''} ${this.name}__input`, ref: el => this.stylingContainer = el }, h("div", { key: 'e2885669879d0b61473be48014975859d87b2478', class: 'password__wrapper--flex' }, h("label", { key: 'c12f0a0bfe91a9da9688ab0acd39f6a44eec5d0a', class: `password__label ${this.validation.mandatory ? 'password__label--required' : ''}`, htmlFor: `${this.name}__input` }, this.displayName), h("div", { key: 'f501cb74b838d2c4a1a1fd38086203e4b1c98dfe', class: 'password__wrapper--relative' }, this.tooltip &&
6315
- h("img", { key: '68d71061fb6be2245298e521b511e57b4cb12cbb', class: 'password__tooltip-icon', src: tooltipIconSvg, alt: "", ref: (el) => this.tooltipIconReference = el, onClick: () => this.showTooltip = !this.showTooltip }), this.renderTooltip())), h("vaadin-password-field", { key: 'c8e3ce65dc46599cffe9763621b271fc18243829', type: "password", id: `${this.name}__input`, class: `password__input ${invalidClass}`, name: this.name, readOnly: this.autofilled, value: this.defaultValue, required: this.validation.mandatory, maxlength: this.validation.maxLength, minlength: this.validation.minLength, pattern: this.validationPattern, placeholder: `${this.placeholder}`, onInput: this.handleInput, onBlur: this.handleBlur, onFocus: this.handleFocus }), h("small", { key: 'ca4aeae4893276dc96bd7187aef5ac2ed86d35c8', class: 'password__error-message' }, this.errorMessage), this.passwordComplexity && this.showPopup && !this.hidePasswordComplexity && !this.isDuplicateInput && this.renderComplexityPopup());
6291
+ return h("div", { key: '9fd27b840b317bbb224f062c855c4b4a8b94a3a4', class: `password__wrapper ${this.autofilled ? 'password__wrapper--autofilled' : ''} ${this.name}__input`, ref: el => this.stylingContainer = el }, h("div", { key: '3d16837c2e10a490fd07ef1c294db1f5732da4ad', class: 'password__wrapper--flex' }, h("label", { key: '09d61fc66912e7a79b83842e4d6d89b851a92afa', class: `password__label ${this.validation.mandatory ? 'password__label--required' : ''}`, htmlFor: `${this.name}__input` }, this.displayName), h("div", { key: '23f4d60bc9f777d00fd16d2dc78cc7c105307e32', class: 'password__wrapper--relative' }, this.tooltip &&
6292
+ h("img", { key: 'db104e01e0f5d5d322b3394f8740cedaaa8b2199', class: 'password__tooltip-icon', src: tooltipIconSvg, alt: "", ref: (el) => this.tooltipIconReference = el, onClick: () => this.showTooltip = !this.showTooltip }), this.renderTooltip())), h("vaadin-password-field", { key: '072309fd70e0af72bde2beb579e6d93abea8928a', type: "password", id: `${this.name}__input`, class: `password__input ${invalidClass}`, name: this.name, readOnly: this.autofilled, value: this.defaultValue, required: this.validation.mandatory, maxlength: this.validation.maxLength, minlength: this.validation.minLength, placeholder: `${this.placeholder}`, onInput: this.handleInput, onBlur: this.handleBlur, onFocus: this.handleFocus }), h("small", { key: '41336c3bd58eba953266b31980ce0677b27405f0', class: 'password__error-message' }, this.errorMessage), this.passwordComplexity && this.showPopup && !this.hidePasswordComplexity && !this.isDuplicateInput && this.renderComplexityPopup());
6316
6293
  }
6317
6294
  get element() { return getElement(this); }
6318
6295
  static get watchers() { return {
@@ -6633,7 +6610,6 @@ const TelInput = class {
6633
6610
  registerInstance(this, hostRef);
6634
6611
  this.sendValidityState = createEvent(this, "sendValidityState", 7);
6635
6612
  this.sendInputValue = createEvent(this, "sendInputValue", 7);
6636
- this.validationPattern = '';
6637
6613
  this.touched = false;
6638
6614
  this.handleInput = (event) => {
6639
6615
  const inputElement = event.target;
@@ -6647,15 +6623,13 @@ const TelInput = class {
6647
6623
  clearTimeout(this.debounceTime);
6648
6624
  }
6649
6625
  this.debounceTime = setTimeout(() => {
6650
- this.isValid = this.setValidity();
6651
- this.errorMessage = this.setErrorMessage();
6626
+ this.updateValidity();
6652
6627
  this.emitValueHandler(true);
6653
6628
  }, 500);
6654
6629
  };
6655
6630
  this.handleBlur = () => {
6656
6631
  if (!this.touched) {
6657
- this.isValid = this.setValidity();
6658
- this.errorMessage = this.setErrorMessage();
6632
+ this.updateValidity();
6659
6633
  this.touched = true;
6660
6634
  }
6661
6635
  };
@@ -6710,7 +6684,6 @@ const TelInput = class {
6710
6684
  }
6711
6685
  }
6712
6686
  connectedCallback() {
6713
- this.validationPattern = this.setPattern();
6714
6687
  if (this.defaultValue) {
6715
6688
  this.prefixValue = this.defaultValue.prefix ? this.defaultValue.prefix : this.defaultValue;
6716
6689
  this.phoneValue = this.defaultValue.phone || null;
@@ -6740,7 +6713,7 @@ const TelInput = class {
6740
6713
  // end custom styling area
6741
6714
  }
6742
6715
  componentDidLoad() {
6743
- this.isValid = this.setValidity();
6716
+ this.isValid = this.validate().isValid;
6744
6717
  if (this.defaultValue) {
6745
6718
  this.value = this.defaultValue;
6746
6719
  this.valueHandler({ name: this.name, value: this.value, type: 'tel' });
@@ -6764,28 +6737,27 @@ const TelInput = class {
6764
6737
  this.value = { prefix: this.prefixValue, phone: this.phoneValue };
6765
6738
  this.emitValueHandler(true);
6766
6739
  }
6767
- setValidity() {
6768
- return this.inputReference.validity.valid;
6769
- }
6770
- setPattern() {
6771
- var _a, _b;
6772
- if (((_a = this.validation.custom) === null || _a === void 0 ? void 0 : _a.length) > 0) {
6773
- return (_b = this.validation.custom.find(customValidation => customValidation.rule === 'regex')) === null || _b === void 0 ? void 0 : _b.pattern;
6740
+ validate() {
6741
+ if (!this.inputReference) {
6742
+ return { isValid: false, errorMessage: '' };
6774
6743
  }
6775
- }
6776
- setErrorMessage() {
6777
- var _a, _b;
6778
- if (this.inputReference.validity.patternMismatch) {
6779
- const errorCode = (_a = this.validation.custom.find(customValidation => customValidation.rule === 'regex')) === null || _a === void 0 ? void 0 : _a.errorKey;
6780
- const errorMessage = (_b = this.validation.custom.find(customValidation => customValidation.rule === 'regex')) === null || _b === void 0 ? void 0 : _b.errorMessage;
6781
- return translate(`${errorCode}`, this.language) ? translate(`${errorCode}`, this.language) : errorMessage;
6744
+ const value = this.inputReference.value;
6745
+ const failedRule = value ? getFailedRegexRule(value, this.validation.custom) : undefined;
6746
+ if (failedRule) {
6747
+ return { isValid: false, errorMessage: getRuleErrorMessage(failedRule, this.language) };
6782
6748
  }
6783
6749
  if (this.inputReference.validity.tooShort || this.inputReference.validity.tooLong) {
6784
- return translate('lengthError', this.language, { values: { minLength: this.validation.minLength, maxLength: this.validation.maxLength } });
6750
+ return { isValid: false, errorMessage: translate('lengthError', this.language, { values: { minLength: this.validation.minLength, maxLength: this.validation.maxLength } }) };
6785
6751
  }
6786
6752
  if (this.inputReference.validity.valueMissing) {
6787
- return translate('requiredError', this.language);
6753
+ return { isValid: false, errorMessage: translate('requiredError', this.language) };
6788
6754
  }
6755
+ return { isValid: this.inputReference.validity.valid, errorMessage: '' };
6756
+ }
6757
+ updateValidity() {
6758
+ const { isValid, errorMessage } = this.validate();
6759
+ this.isValid = isValid;
6760
+ this.errorMessage = errorMessage;
6789
6761
  }
6790
6762
  renderTooltip() {
6791
6763
  if (this.showTooltip) {
@@ -6798,8 +6770,8 @@ const TelInput = class {
6798
6770
  if (this.touched) {
6799
6771
  invalidClass = this.isValid == true || this.isValid == undefined ? '' : 'text__input--invalid';
6800
6772
  }
6801
- return h("div", { key: '8a75a1a66dae4a9f453487be42c8563fc94c9338', class: `tel__wrapper ${this.autofilled ? 'tel__wrapper--autofilled' : ''} ${this.name}__input`, ref: el => this.stylingContainer = el }, h("div", { key: '01589400f59390352949240162a96874be011f03', class: 'tel__wrapper--flex-label' }, h("label", { key: '73beb8ce7ea80ea4fca24db633e021dbab04f9ba', class: `tel__label ${this.validation.mandatory ? 'tel__label--required' : ''}`, htmlFor: `${this.name}__input` }, this.displayName), h("div", { key: '56eaf52390a9dd93342324a1bf87a1b7a9f04b97', class: 'tel__wrapper--relative' }, this.tooltip &&
6802
- h("img", { key: '198fc851fb3ea4763607cfe2b0e08414e07adfe5', class: 'tel__tooltip-icon', src: tooltipIconSvg, alt: "", ref: (el) => this.tooltipIconReference = el, onClick: () => this.showTooltip = !this.showTooltip }), this.renderTooltip())), h("div", { key: '4cbf87d5e3be55ce0d23ec1ab223e168e4991a9f', class: `tel__wrapper--flex ${invalidClass}` }, h("vaadin-combo-box", { key: '3898ad1468b4f03d4ebaf24d0898e70988663f6d', class: 'tel__prefix', items: this.phoneCodesOptions, value: this.prefixValue, readOnly: this.autofilled, onChange: (e) => this.handlePrefixInput(e) }), h("input", { key: '24794f3651771ffbb011ef2048b28b4bc7cba0c7', type: "tel", ref: (el) => this.inputReference = el, id: `${this.name}__input`, readOnly: this.autofilled, class: `tel__input`, value: this.phoneValue, placeholder: `${this.placeholder}`, required: this.validation.mandatory, minlength: this.validation.minLength, maxlength: this.validation.maxLength, pattern: this.validationPattern, onInput: this.handleInput, onBlur: this.handleBlur })), h("small", { key: 'a33de6b2bec2b9dd79fa9960a7bbacc9845d8c51', class: 'tel__error-message' }, this.errorMessage));
6773
+ return h("div", { key: '78ddea111a011a7c75df7a6f7101aafccbaff4a1', class: `tel__wrapper ${this.autofilled ? 'tel__wrapper--autofilled' : ''} ${this.name}__input`, ref: el => this.stylingContainer = el }, h("div", { key: '9dcd9723ed26de04630a8a174e902a629bc9347c', class: 'tel__wrapper--flex-label' }, h("label", { key: '597e8a28990f12e1183fdeb315e176af970d4104', class: `tel__label ${this.validation.mandatory ? 'tel__label--required' : ''}`, htmlFor: `${this.name}__input` }, this.displayName), h("div", { key: '86c147c124468d06bffdf8359c7f404cbe897c15', class: 'tel__wrapper--relative' }, this.tooltip &&
6774
+ h("img", { key: '0d2b528570401361087bf0438493a96a3450e40c', class: 'tel__tooltip-icon', src: tooltipIconSvg, alt: "", ref: (el) => this.tooltipIconReference = el, onClick: () => this.showTooltip = !this.showTooltip }), this.renderTooltip())), h("div", { key: 'd82808bbc28c720ae4cff45fd1d0df88ca320029', class: `tel__wrapper--flex ${invalidClass}` }, h("vaadin-combo-box", { key: '73805b42a6b40d901e6367e45e4d6d1ff2288082', class: 'tel__prefix', items: this.phoneCodesOptions, value: this.prefixValue, readOnly: this.autofilled, onChange: (e) => this.handlePrefixInput(e) }), h("input", { key: '483f7fd3f8e71d3ab9161b66d6584bd141e56144', type: "tel", ref: (el) => this.inputReference = el, id: `${this.name}__input`, readOnly: this.autofilled, class: `tel__input`, value: this.phoneValue, placeholder: `${this.placeholder}`, required: this.validation.mandatory, minlength: this.validation.minLength, maxlength: this.validation.maxLength, onInput: this.handleInput, onBlur: this.handleBlur })), h("small", { key: '296651863f2d6fcf31eb21f2d83b7df505d59833', class: 'tel__error-message' }, this.errorMessage));
6803
6775
  }
6804
6776
  static get watchers() { return {
6805
6777
  "clientStyling": ["handleStylingChange"],
@@ -6818,7 +6790,6 @@ const TextInput = class {
6818
6790
  this.sendValidityState = createEvent(this, "sendValidityState", 7);
6819
6791
  this.sendInputValue = createEvent(this, "sendInputValue", 7);
6820
6792
  this.value = '';
6821
- this.validationPattern = [];
6822
6793
  this.duplicateInputValue = null;
6823
6794
  this.handleInput = (event) => {
6824
6795
  const inputElement = event.target;
@@ -6832,8 +6803,7 @@ const TextInput = class {
6832
6803
  clearTimeout(this.debounceTime);
6833
6804
  }
6834
6805
  this.debounceTime = setTimeout(() => {
6835
- this.isValid = this.setValidity();
6836
- this.errorMessage = this.setErrorMessage();
6806
+ this.updateValidity();
6837
6807
  this.validityStateHandler({ valid: this.isValid, name: this.name });
6838
6808
  this.emitValueHandler(true);
6839
6809
  }, 500);
@@ -6841,8 +6811,7 @@ const TextInput = class {
6841
6811
  this.handleBlur = (event) => {
6842
6812
  this.value = event.target.value;
6843
6813
  this.touched = true;
6844
- this.isValid = this.setValidity();
6845
- this.errorMessage = this.setErrorMessage();
6814
+ this.updateValidity();
6846
6815
  this.validityStateHandler({ valid: this.isValid, name: this.name });
6847
6816
  };
6848
6817
  this.setClientStyling = () => {
@@ -6873,10 +6842,11 @@ const TextInput = class {
6873
6842
  if (newValue) {
6874
6843
  this.value = newValue;
6875
6844
  requestAnimationFrame(() => {
6876
- this.isValid = this.setValidity();
6877
- if (!this.isValid && !this.touched) {
6845
+ const { isValid, errorMessage } = this.validate();
6846
+ this.isValid = isValid;
6847
+ if (!isValid && !this.touched) {
6878
6848
  this.touched = true;
6879
- this.errorMessage = this.setErrorMessage();
6849
+ this.errorMessage = errorMessage;
6880
6850
  }
6881
6851
  });
6882
6852
  }
@@ -6912,15 +6882,13 @@ const TextInput = class {
6912
6882
  if (this.isDuplicateInput && this.name === event.detail.name + 'Duplicate') {
6913
6883
  this.duplicateInputValue = event.detail.value;
6914
6884
  if (this.touched) {
6915
- this.isValid = this.setValidity();
6916
- this.errorMessage = this.setErrorMessage();
6885
+ this.updateValidity();
6917
6886
  }
6918
6887
  }
6919
6888
  if (this.name === event.detail.name + 'Duplicate'
6920
6889
  && this.name.replace('Duplicate', '') === event.detail.name
6921
6890
  && this.touched === true) {
6922
- this.isValid = this.setValidity();
6923
- this.errorMessage = this.setErrorMessage();
6891
+ this.updateValidity();
6924
6892
  }
6925
6893
  }
6926
6894
  handleValidationChange(event) {
@@ -6928,15 +6896,10 @@ const TextInput = class {
6928
6896
  return;
6929
6897
  }
6930
6898
  this.validation = event.detail.validation;
6931
- this.validationPattern = this.setPattern();
6932
6899
  if (this.touched) {
6933
- this.isValid = this.setValidity();
6934
- this.errorMessage = this.setErrorMessage();
6900
+ this.updateValidity();
6935
6901
  }
6936
6902
  }
6937
- connectedCallback() {
6938
- this.validationPattern = this.setPattern();
6939
- }
6940
6903
  componentDidRender() {
6941
6904
  // start custom styling area
6942
6905
  if (!this.limitStylingAppends && this.stylingContainer) {
@@ -6953,7 +6916,7 @@ const TextInput = class {
6953
6916
  this.validation.minLength &&
6954
6917
  this.inputReference.value.length < this.validation.minLength) {
6955
6918
  this.touched = true;
6956
- this.errorMessage = this.setErrorMessage();
6919
+ this.errorMessage = this.validate().errorMessage;
6957
6920
  }
6958
6921
  }
6959
6922
  componentDidLoad() {
@@ -6964,54 +6927,40 @@ const TextInput = class {
6964
6927
  this.touched = true;
6965
6928
  }
6966
6929
  }
6967
- this.isValid = this.setValidity();
6930
+ this.isValid = this.validate().isValid;
6968
6931
  }
6969
- setValidity() {
6970
- if (this.isDuplicateInput && this.duplicateInputValue !== this.value) {
6971
- return false;
6972
- }
6932
+ updateValidity() {
6933
+ const { isValid, errorMessage } = this.validate();
6934
+ this.isValid = isValid;
6935
+ this.errorMessage = errorMessage;
6936
+ }
6937
+ validate() {
6938
+ var _a;
6973
6939
  if (!this.inputReference) {
6974
- return false;
6940
+ return { isValid: false, errorMessage: '' };
6975
6941
  }
6976
6942
  const inputValue = this.inputReference.value;
6977
- const inputIsValid = this.inputReference.validity.valid;
6978
- const inputMatchValidation = !inputValue
6979
- || (this.validationPattern.length > 0 ? this.validationPattern.some((pattern) => inputValue.match(pattern) !== null) : true);
6980
- // Fallback: if HTML5 says valid but minlength constraint not met, it's invalid
6981
- const isTooShort = this.validation.minLength && inputValue.length > 0 && inputValue.length < this.validation.minLength;
6982
- return !isTooShort && inputIsValid && inputMatchValidation;
6983
- }
6984
- setPattern() {
6985
- const custom = this.validation.custom;
6986
- if (!(custom === null || custom === void 0 ? void 0 : custom.length))
6987
- return [];
6988
- return custom
6989
- .filter(v => v.rule === 'regex')
6990
- .map(v => v.pattern);
6991
- }
6992
- setErrorMessage() {
6993
- var _a, _b;
6994
- const inputValue = this.inputReference.value;
6995
6943
  if (this.inputReference.validity.valueMissing) {
6996
- return translate('requiredError', this.language);
6944
+ return { isValid: false, errorMessage: translate('requiredError', this.language) };
6997
6945
  }
6998
6946
  // Check length manually (fallback for HTML5 validation API issues)
6999
6947
  const isTooShort = this.validation.minLength && inputValue.length > 0 && inputValue.length < this.validation.minLength;
7000
6948
  const isTooLong = this.validation.maxLength && inputValue.length > this.validation.maxLength;
7001
6949
  if (this.inputReference.validity.tooShort || this.inputReference.validity.tooLong || isTooShort || isTooLong) {
7002
- return translate('lengthError', this.language, { values: { minLength: this.validation.minLength, maxLength: this.validation.maxLength } });
6950
+ return {
6951
+ isValid: false,
6952
+ errorMessage: translate('lengthError', this.language, { values: { minLength: this.validation.minLength, maxLength: this.validation.maxLength } })
6953
+ };
7003
6954
  }
7004
- const isCustomError = !(inputValue === '' && !this.validation.mandatory)
7005
- && (this.validationPattern.length > 0 ? this.validationPattern.some((pattern) => inputValue.match(pattern) == null) : false);
7006
- if (isCustomError) {
7007
- const { errorKey: errorCode, errorMessage } = this.validation.custom.find(customValidation => customValidation.rule === 'regex');
7008
- return translate(`${errorCode}`, this.language) || errorMessage;
6955
+ const failedRegexRule = inputValue ? getFailedRegexRule(inputValue, this.validation.custom) : undefined;
6956
+ if (failedRegexRule) {
6957
+ return { isValid: false, errorMessage: getRuleErrorMessage(failedRegexRule, this.language) };
7009
6958
  }
7010
6959
  if (this.isDuplicateInput && this.duplicateInputValue !== this.value) {
7011
- const errorCode = (_a = this.validation.custom.find(customRule => customRule.rule === 'duplicate-input')) === null || _a === void 0 ? void 0 : _a.errorKey;
7012
- const errorMessage = (_b = this.validation.custom.find(customRule => customRule.rule === 'duplicate-input')) === null || _b === void 0 ? void 0 : _b.errorMessage;
7013
- return translate(`${errorCode}`, this.language) ? translate(`${errorCode}`, this.language) : errorMessage;
6960
+ const duplicateRule = (_a = this.validation.custom) === null || _a === void 0 ? void 0 : _a.find(customRule => customRule.rule === 'duplicate-input');
6961
+ return { isValid: false, errorMessage: duplicateRule ? getRuleErrorMessage(duplicateRule, this.language) : '' };
7014
6962
  }
6963
+ return { isValid: this.inputReference.validity.valid, errorMessage: '' };
7015
6964
  }
7016
6965
  renderTooltip() {
7017
6966
  if (this.showTooltip) {
@@ -7024,8 +6973,8 @@ const TextInput = class {
7024
6973
  if (this.touched) {
7025
6974
  invalidClass = this.isValid == true || this.isValid == undefined ? '' : 'text__input--invalid';
7026
6975
  }
7027
- return h("div", { key: '045e3183bdb1c7279abbd045043d789387956de5', class: `text__wrapper ${this.name}__input ${this.autofilled ? 'text__wrapper--autofilled' : ''}`, ref: el => this.stylingContainer = el }, h("div", { key: '3534d1261f9ccb9c0942f01d0758d9fd65743e40', class: 'text__wrapper--flex' }, h("label", { key: '171155d911e2c1048b003be8541671f0cdeb1ce5', class: `text__label ${this.validation.mandatory ? 'text__label--required' : ''}`, htmlFor: `${this.name}__input` }, this.displayName), h("div", { key: '8a0b0abe15eaf77b5efc5fa6374a8faeea24cf94', class: 'text__wrapper--relative' }, this.tooltip &&
7028
- h("img", { key: 'aa0b0b33cdb370289db8444c3dba915ef8eb77be', class: 'text__tooltip-icon', src: tooltipIconSvg, alt: "", ref: (el) => this.tooltipIconReference = el, onClick: () => this.showTooltip = !this.showTooltip }), this.renderTooltip())), h("input", { key: 'cc47bb443384396eefd7bf61f767f8646f7e2639', name: this.name, id: `${this.name}__input`, value: this.defaultValue, type: 'text', class: `text__input ${invalidClass}`, placeholder: `${this.placeholder}`, ref: (el) => this.inputReference = el, readOnly: this.autofilled, required: this.validation.mandatory, minlength: this.validation.minLength, maxlength: this.validation.maxLength, onInput: this.handleInput, onBlur: this.handleBlur }), h("small", { key: 'ce7b97e0a7db8eb87c608690bad3cf99a565ba9f', class: 'text__error-message' }, this.errorMessage));
6976
+ return h("div", { key: '206f2e3c3cf18b4405c07be422bb6173ac3a2ac2', class: `text__wrapper ${this.name}__input ${this.autofilled ? 'text__wrapper--autofilled' : ''}`, ref: el => this.stylingContainer = el }, h("div", { key: 'b6aa572d3f984a386a850b3f968a674eb94f7816', class: 'text__wrapper--flex' }, h("label", { key: '7fba5554aac3af6444225cb6da166276470dba50', class: `text__label ${this.validation.mandatory ? 'text__label--required' : ''}`, htmlFor: `${this.name}__input` }, this.displayName), h("div", { key: '9677b43f2f5e185e4d7fcfe007dd73a16d50876b', class: 'text__wrapper--relative' }, this.tooltip &&
6977
+ h("img", { key: '69360ef5dd851cf64110f82189c2a27f99c843f8', class: 'text__tooltip-icon', src: tooltipIconSvg, alt: "", ref: (el) => this.tooltipIconReference = el, onClick: () => this.showTooltip = !this.showTooltip }), this.renderTooltip())), h("input", { key: '46b8d857acfb2d4fdd874984f555fc4457b7d53f', name: this.name, id: `${this.name}__input`, value: this.defaultValue, type: 'text', class: `text__input ${invalidClass}`, placeholder: `${this.placeholder}`, ref: (el) => this.inputReference = el, readOnly: this.autofilled, required: this.validation.mandatory, minlength: this.validation.minLength, maxlength: this.validation.maxLength, onInput: this.handleInput, onBlur: this.handleBlur }), h("small", { key: '5db72a6b2c969e3af37eaf03ce3a77524a5f25d2', class: 'text__error-message' }, this.errorMessage));
7029
6978
  }
7030
6979
  static get watchers() { return {
7031
6980
  "defaultValue": ["handleDefaultValueChange"],
@@ -7154,7 +7103,6 @@ const TwofaInput = class {
7154
7103
  this.sendValidityState = createEvent(this, "sendValidityState", 7);
7155
7104
  this.sendInputValue = createEvent(this, "sendInputValue", 7);
7156
7105
  this.resendCode = createEvent(this, "resendCode", 7);
7157
- this.validationPattern = '';
7158
7106
  this.stylingContainer = null;
7159
7107
  this.tooltipReference = null;
7160
7108
  this.tooltipIconReference = null;
@@ -7213,8 +7161,7 @@ const TwofaInput = class {
7213
7161
  if (nextInput) {
7214
7162
  nextInput.focus();
7215
7163
  }
7216
- this.setValidity();
7217
- this.setErrorMessage();
7164
+ this.updateValidity();
7218
7165
  };
7219
7166
  this.setClientStyling = () => {
7220
7167
  let sheet = document.createElement('style');
@@ -7267,7 +7214,6 @@ const TwofaInput = class {
7267
7214
  }
7268
7215
  }
7269
7216
  connectedCallback() {
7270
- this.validationPattern = this.setPattern();
7271
7217
  this.code = new Array(this.validation.maxLength).fill('');
7272
7218
  }
7273
7219
  componentDidRender() {
@@ -7279,7 +7225,7 @@ const TwofaInput = class {
7279
7225
  }
7280
7226
  }
7281
7227
  componentDidLoad() {
7282
- this.setValidity();
7228
+ this.isValid = this.validate().isValid;
7283
7229
  }
7284
7230
  handleKeyDown(e, idx) {
7285
7231
  if (e.key === 'Backspace') {
@@ -7292,8 +7238,7 @@ const TwofaInput = class {
7292
7238
  prevInput === null || prevInput === void 0 ? void 0 : prevInput.focus();
7293
7239
  }
7294
7240
  }
7295
- this.setValidity();
7296
- this.setErrorMessage();
7241
+ this.updateValidity();
7297
7242
  }
7298
7243
  handlePaste(e) {
7299
7244
  var _a;
@@ -7312,33 +7257,20 @@ const TwofaInput = class {
7312
7257
  if (lastInput) {
7313
7258
  lastInput.focus();
7314
7259
  }
7315
- this.setValidity();
7316
- this.setErrorMessage();
7260
+ this.updateValidity();
7317
7261
  }
7318
- setValidity() {
7262
+ validate() {
7319
7263
  const code = this.code.join('');
7320
- const inputMatchLength = code.length === this.validation.maxLength;
7321
- const inputMatchValidation = code.match(this.validationPattern) !== null;
7322
- this.isValid = inputMatchLength && inputMatchValidation;
7323
- }
7324
- setPattern() {
7325
- var _a, _b;
7326
- if (((_a = this.validation.custom) === null || _a === void 0 ? void 0 : _a.length) > 0) {
7327
- return (_b = this.validation.custom.find(customValidation => customValidation.rule === 'regex')) === null || _b === void 0 ? void 0 : _b.pattern;
7328
- }
7264
+ const failedRule = getFailedRegexRule(code, this.validation.custom);
7265
+ return {
7266
+ isValid: code.length === this.validation.maxLength && !failedRule,
7267
+ errorMessage: failedRule ? getRuleErrorMessage(failedRule, this.language) : ''
7268
+ };
7329
7269
  }
7330
- setErrorMessage() {
7331
- var _a;
7332
- const inputMatchValidation = this.code.join('').match(this.validationPattern) !== null;
7333
- if (!inputMatchValidation) {
7334
- const errorKey = (_a = this.validation.custom.find(customValidation => customValidation.rule === 'regex')) === null || _a === void 0 ? void 0 : _a.errorKey;
7335
- if (errorKey) {
7336
- this.errorMessage = translate(errorKey, this.language);
7337
- }
7338
- }
7339
- else {
7340
- this.errorMessage = '';
7341
- }
7270
+ updateValidity() {
7271
+ const { isValid, errorMessage } = this.validate();
7272
+ this.isValid = isValid;
7273
+ this.errorMessage = errorMessage;
7342
7274
  }
7343
7275
  renderTooltip() {
7344
7276
  if (this.showTooltip) {
@@ -7347,9 +7279,9 @@ const TwofaInput = class {
7347
7279
  return null;
7348
7280
  }
7349
7281
  render() {
7350
- return (h("div", { key: '5764336a8995a1ec0e7ff432ce85c8a317e3f01c', class: "twofa" }, h("div", { key: '8ea47ba6bb5f552afcde936f1de8c544f89e12a7', class: 'twofa__error-message' }, h("p", { key: '6930908b1f5df7030d96a442779203747aa938b2' }, this.errorMessage)), h("div", { key: '56f116fa0ac4883d1b225b7165b2d5271a661d9d', class: "twofa__description", innerHTML: translate('twofaDescription', this.language, { values: { destination: this.destination } }) }), h("div", { key: 'b2ecadecbc8802c5b4dd09d81dc77e66f2108990', class: "twofa__input-wrapper", ref: this.setContainerRef }, this.code.map((char, idx) => {
7282
+ return (h("div", { key: '31164396a440bde033871a5cbf651546895d8c3d', class: "twofa" }, h("div", { key: 'cc50746fb709c3853cd11fd13c68be93efd811b4', class: 'twofa__error-message' }, h("p", { key: '4a34b178dd4b018daf81ee654f91f79813f801db' }, this.errorMessage)), h("div", { key: '0ac2a794fcb27deb3f40b87fe4758e19e35b53b2', class: "twofa__description", innerHTML: translate('twofaDescription', this.language, { values: { destination: this.destination } }) }), h("div", { key: '69fdbfc5be1af6fab8b386179eaa25ea181aec3a', class: "twofa__input-wrapper", ref: this.setContainerRef }, this.code.map((char, idx) => {
7351
7283
  return (h("input", { key: idx, ref: el => this.setInputRef(el, idx), id: `otp-input-${idx}`, type: "text", maxLength: 2, value: char, onInput: (event) => this.handleInput(event, idx), onKeyDown: (event) => this.handleKeyDown(event, idx), onPaste: (event) => this.handlePaste(event) }));
7352
- })), h("div", { key: '76635a96eb73d77a3259f26d7d74f738e705acf1', class: "twofa__button-wrapper" }, h("p", { key: '66b15896c126c4c7e8d3ba6d22829992df4cfde9', class: "twofa__resend-message" }, translate('twofaResendMessage', this.language)), h("button", { key: '7e81ec829cfeb48e911d7b88aa9ec7d6f1cbf4e2', class: "twofa__resend-button", onClick: this.resendCodeHandler, disabled: !this.isResendButtonAvailable }, this.isResendButtonAvailable
7284
+ })), h("div", { key: '9a9f50ed47da2204cd31a27939d18b42011a1114', class: "twofa__button-wrapper" }, h("p", { key: 'ad90ba428278f90a05f706c67452551f3c75a199', class: "twofa__resend-message" }, translate('twofaResendMessage', this.language)), h("button", { key: 'cead0e523e873c20dd21982e318b1e37998480b8', class: "twofa__resend-button", onClick: this.resendCodeHandler, disabled: !this.isResendButtonAvailable }, this.isResendButtonAvailable
7353
7285
  ? translate('twofaResendButton', this.language)
7354
7286
  : this.formatTime()))));
7355
7287
  }