Skip to content

Commit

Permalink
Add new special class "enableHiddenMessageClass" (thanks zakrava)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
Robyer committed Sep 25, 2015
1 parent 68ee03b commit 51df1b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion live-form-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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';
}

Expand Down

0 comments on commit 51df1b2

Please sign in to comment.