From 81e54f45deabe222002e886eef58f966c9963227 Mon Sep 17 00:00:00 2001 From: Hardik Pithva Date: Thu, 31 Oct 2024 15:25:49 +0100 Subject: [PATCH] fix(form-core): make use of `validatorName` and `type` to check validator instance --- .../ui/components/form-core/src/validate/ValidateMixin.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/ui/components/form-core/src/validate/ValidateMixin.js b/packages/ui/components/form-core/src/validate/ValidateMixin.js index 14f7e96e9e..fec0b2b915 100644 --- a/packages/ui/components/form-core/src/validate/ValidateMixin.js +++ b/packages/ui/components/form-core/src/validate/ValidateMixin.js @@ -10,7 +10,6 @@ import { SyncUpdatableMixin } from '../utils/SyncUpdatableMixin.js'; import { LionValidationFeedback } from './LionValidationFeedback.js'; import { ResultValidator as MetaValidator } from './ResultValidator.js'; import { Unparseable } from './Unparseable.js'; -import { Validator } from './Validator.js'; import { Required } from './validators/Required.js'; import { FormControlMixin } from '../FormControlMixin.js'; @@ -460,7 +459,9 @@ export const ValidateMixinImplementation = superclass => if (isEmpty) { const hasSingleValue = !(/** @type {* & ValidateHost} */ (this)._isFormOrFieldset); - const requiredValidator = this._allValidators.find(v => v instanceof Required); + const requiredValidator = this._allValidators.find( + v => /** @type {typeof Validator} */ (v.constructor)?.validatorName === 'Required', + ); if (requiredValidator) { this.__syncValidationResult = [{ validator: requiredValidator, outcome: true }]; } @@ -685,7 +686,7 @@ export const ValidateMixinImplementation = superclass => } for (const validatorToSetup of this._allValidators) { - if (!(validatorToSetup instanceof Validator)) { + if (validatorToSetup.type === undefined) { // throws in constructor are not visible to end user so we do both const errorType = Array.isArray(validatorToSetup) ? 'array' : typeof validatorToSetup; const errorMessage = `Validators array only accepts class instances of Validator. Type "${errorType}" found. This may be caused by having multiple installations of "@lion/ui/form-core.js".`;