Skip to content

Commit ce511f9

Browse files
committed
Added support for injecting validation-errors directive on input element with data-ng-model.
1 parent e297a2e commit ce511f9

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

dist/bootstrap-angular-validation.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/directives/validation.directive.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ angular.module("bootstrap.angular.validation").directive("bsValidation", ["$inte
3636
// Search parent element with class form-group to operate on.
3737
var formGroupElement = $element.parents(".form-group");
3838

39+
// Search for an attribute "form-group" if the class ".form-group" is not available
40+
if (!formGroupElement || formGroupElement.length === 0) {
41+
formGroupElement = $element.parents("[form-group]");
42+
}
43+
3944
/*
4045
* Used to resolve the message for current validation failure. Will first search the title attribute
4146
* with the validation key and then fallback to use the default message.
@@ -67,7 +72,7 @@ angular.module("bootstrap.angular.validation").directive("bsValidation", ["$inte
6772
formGroupElement.removeClass("has-error");
6873

6974
if (formGroupElement.length > 0) {
70-
formGroupElement.findAll("span." + errorClasses.join(".")).remove();
75+
formGroupElement.findAll("span." + errorClasses.join(".")).addClass("ng-hide");
7176
}
7277
return false;
7378
}
@@ -106,7 +111,7 @@ angular.module("bootstrap.angular.validation").directive("bsValidation", ["$inte
106111
insertAfter.after(errorMarkup);
107112
} else {
108113
// Else change the message.
109-
errorElement.html(iconMarkup + message);
114+
errorElement.html(iconMarkup + message).removeClass("ng-hide");
110115
}
111116

112117
// Mark that, first error is displayed. TODO Can use a much cleaner solution.

src/services/validation.service.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,15 @@ angular.module("bootstrap.angular.validation").factory("BsValidationService", fu
7272
ngModelController.$setValidity(key, isValid);
7373
}
7474

75-
var selector = "input[ng-model],select[ng-model],textarea[ng-model]";
75+
var selectors = [];
76+
var elements = ["input", "select", "textarea"];
77+
78+
angular.forEach(elements, function(element) {
79+
selectors.push(element + "[ng-model]");
80+
selectors.push(element + "[data-ng-model]");
81+
});
82+
83+
var selector = selectors.join(",");
7684

7785
return {
7886
/**

0 commit comments

Comments
 (0)