Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Jul 1, 2020. It is now read-only.

IsErrorMessageVisible

Ghislain B edited this page Jan 19, 2017 · 4 revisions

version 1.5.15+

In some cases, you might to know if the error message is shown or not and depending on that do other things. Thanks to the user @Gusi you can now do it in a simple way. A new flag isErrorMessageVisible was created for that usage, see below for a use case.

Use Case

(function() {   
   var bootstrapValidationDecorator = function() {
       return {
           scope: {
               bootstrapValidationDecorator:'@'
           },
           restrict: 'A',
           require:  '^form',
           link: function (scope, el, attrs, formCtrl) {
               scope.form = formCtrl; // no template so no need for that for now
               console.log(scope.form);

               if(scope.bootstrapValidationDecorator!=undefined && scope.bootstrapValidationDecorator!="") {
                   scope.fieldName = scope.bootstrapValidationDecorator;
               } else {                    
                   scope.fieldName = angular.element( el[0].querySelector("[name]") ).attr('name');
               }

               scope.$watch(
                   function(scope) {
                       return scope.form[scope.fieldName].isErrorMessageVisible; // NEW
                   },
                   function( newVal, oldVal ) {
                       if(newVal != oldVal){
                           el.toggleClass('has-error', newVal === true); // NEW
                       }
                   }
               );
           }
       }
   }
   angular.module('app').directive('bootstrapValidationDecorator', bootstrapValidationDecorator);

}());

Clone this wiki locally

Morty Proxy This is a proxified and sanitized view of the page, visit original site.