From 8178dfccf0ec7dc24a95f34257143dc4762031d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20=C5=A0=C5=AFstek?= Date: Mon, 26 Aug 2024 12:43:52 +0200 Subject: [PATCH 1/3] custom highlight / unhighlight --- README.MD | 9 +++++++++ src/index.ts | 30 ++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/README.MD b/README.MD index 6703b99..c9cce5d 100644 --- a/README.MD +++ b/README.MD @@ -280,6 +280,15 @@ v.ValidationMessageValidCssClassName = 'valid-feedback'; // change v.bootstrap(); ``` +## Customizing highlight and unhighlight functions + +```js +var v = new aspnetValidation.ValidationService(); +v.highlight = function (input, errorClass, validClass) { ... }; +v.unhighlight = function (input, errorClass, validClass) { ... }; +v.bootstrap(); +``` + ## Logging There is a rudimentary logging infrastructure in place if you want to get more insight into what the library is doing. diff --git a/src/index.ts b/src/index.ts index ad1a309..b8a493f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1252,9 +1252,10 @@ export class ValidationService { } } - this.swapClasses(input, + this.highlight(input, this.ValidationInputCssClassName, - this.ValidationInputValidCssClassName); + this.ValidationInputValidCssClassName + ); if (input.form) { // Adding an error to one input should also add it to others with the same name (i.e. for radio button and checkbox lists). @@ -1287,9 +1288,10 @@ export class ValidationService { } } - this.swapClasses(input, + this.unhighlight(input, + this.ValidationInputCssClassName, this.ValidationInputValidCssClassName, - this.ValidationInputCssClassName); + ); // Removing an error from one input should also remove it from others with the same name (i.e. for radio button and checkbox lists). if (input.form) { @@ -1513,6 +1515,26 @@ export class ValidationService { } } + /** + * Highlights invalid element by adding errorClass CSS class and removing validClass CSS class + * @param input Element to modify + * @param errorClass Class to add + * @param validClass Class to remove + */ + highlight(input : ValidatableElement, errorClass: string, validClass: string) { + this.swapClasses(input, errorClass, validClass); + } + + /** + * Unhighlight valid element by removing errorClass CSS class and adding validClass CSS class + * @param input Element to modify + * @param errorClass Class to add + * @param validClass Class to remove + */ + unhighlight(input: ValidatableElement, errorClass: string, validClass: string) { + this.swapClasses(input, validClass, errorClass); + } + /** * Override CSS class name for input validation error. Default: 'input-validation-error' */ From 44566116a04d18f55f265de446003d38291a08b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20=C5=A0=C5=AFstek?= Date: Mon, 26 Aug 2024 12:46:07 +0200 Subject: [PATCH 2/3] reformat --- src/index.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index b8a493f..4cddd54 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1254,8 +1254,7 @@ export class ValidationService { this.highlight(input, this.ValidationInputCssClassName, - this.ValidationInputValidCssClassName - ); + this.ValidationInputValidCssClassName); if (input.form) { // Adding an error to one input should also add it to others with the same name (i.e. for radio button and checkbox lists). @@ -1290,8 +1289,7 @@ export class ValidationService { this.unhighlight(input, this.ValidationInputCssClassName, - this.ValidationInputValidCssClassName, - ); + this.ValidationInputValidCssClassName); // Removing an error from one input should also remove it from others with the same name (i.e. for radio button and checkbox lists). if (input.form) { From 77a62e6743118c6abd8ca7eeef855effc766967b Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Wed, 4 Sep 2024 09:26:37 -0500 Subject: [PATCH 3/3] Fix docs --- src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 4cddd54..e3472b7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1526,8 +1526,8 @@ export class ValidationService { /** * Unhighlight valid element by removing errorClass CSS class and adding validClass CSS class * @param input Element to modify - * @param errorClass Class to add - * @param validClass Class to remove + * @param errorClass Class to remove + * @param validClass Class to add */ unhighlight(input: ValidatableElement, errorClass: string, validClass: string) { this.swapClasses(input, validClass, errorClass);