IsErrorMessageVisible - ghiscoding/angular-validation GitHub Wiki
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);
}());