From 6319905c1a1fb6e2a8119b1b23b7f83053bc231f Mon Sep 17 00:00:00 2001 From: Phil Haack Date: Tue, 2 Jan 2024 12:42:05 -0800 Subject: [PATCH] Do not validate disabled inputs Fixes #90 --- src/index.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 7f01e8b..75481f9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1234,8 +1234,8 @@ export class ValidationService { */ createValidator(input: ValidatableElement, directives: ValidationDirective) { return async () => { - // only validate visible fields - if (!this.isHidden(input)) { + // only validate visible and enabled fields + if (!this.isHidden(input) && !this.isDisabled(input)) { for (let key in directives) { let directive = directives[key]; let provider = this.providers[key]; @@ -1286,6 +1286,15 @@ export class ValidationService { return !(this.allowHiddenFields || input.offsetWidth || input.offsetHeight || input.getClientRects().length); } + /** + * Checks if the provided input is disabled + * @param input + * @returns + */ + private isDisabled(input: HTMLElement) { + return input.getAttribute('disabled') !== null; + } + /** * Adds addClass and removes removeClass * @param element Element to modify