From 51df1b2bec82e6f0a7e371d058e53839b5280b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Fri, 25 Sep 2015 10:09:32 +0200 Subject: [PATCH] Add new special class "enableHiddenMessageClass" (thanks zakrava) Control with this CSS class will show error/valid message even when control itself is hidden (useful for controls which are hidden and wrapped into special component) --- README.md | 1 + live-form-validation.js | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d7fb635..8c603e5 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Options - **controlErrorClass** - CSS class for an invalid control - **controlValidClass** - CSS class for a valid control - **messageErrorClass** - CSS class for an error message +- **enableHiddenMessageClass** - control with this CSS class will show error/valid message even when control itself is hidden (useful for controls which are hidden and wrapped into special component) - **disableLiveValidationClass** - control with this CSS class will have disabled live validation - **disableShowValidClass** - control with this CSS class will not show valid message - **messageTag** - tag that will hold the error/valid message diff --git a/live-form-validation.js b/live-form-validation.js index 9e3bc14..dede69b 100644 --- a/live-form-validation.js +++ b/live-form-validation.js @@ -20,6 +20,9 @@ var LiveForm = { // CSS class for an error message messageErrorClass: 'help-block text-danger', + // control with this CSS class will show error/valid message even when control itself is hidden (useful for controls which are hidden and wrapped into special component) + enableHiddenMessageClass: 'show-hidden-error', + // control with this CSS class will have disabled live validation disableLiveValidationClass: 'no-live-validation', @@ -139,6 +142,10 @@ LiveForm.processServerErrors = function(el) { }; LiveForm.addError = function(el, message) { + // Ignore elements with disabled live validation + if (this.hasClass(el, this.options.disableLiveValidationClass)) + return; + this.forms[el.form.id].hasError = true; this.addClass(this.getGroupElement(el), this.options.controlErrorClass); @@ -221,7 +228,7 @@ LiveForm.getMessageElement = function(el) { // Message element doesn't exist, lets create a new one messageEl = document.createElement(this.options.messageTag); messageEl.id = id; - if (el.style.display == 'none') { + if (el.style.display == 'none' && !this.hasClass(el, this.options.enableHiddenMessageClass)) { messageEl.style.display = 'none'; }