I want to add a red star before invalid text inputs. Something like
.ng-invalid:before
{
content: "*";
color: Red;
}
unfortunately it seems that :before doesn't always work for input. How to do?
I want to add a red star before invalid text inputs. Something like
.ng-invalid:before
{
content: "*";
color: Red;
}
unfortunately it seems that :before doesn't always work for input. How to do?
removed
edit
You need to put the elements in a div and give that the :before
properties, or just have it in a separate element (the *
) which uses ng-show
for validity.
Misunderstood the question initially, but yes, this.
Thanks. In order to make the solution reusable, I have created the directive: ngErrorShow It adds a star element before the input, and uses ngShow, to show/ hide the star.
portaldirectives.directive("ngErrorShow", function ($compile) {
return {
restrict: 'A',
require: "^form",
link: function (scope, element, attrs, ctrl) {
var varName = ctrl.$name + "." + attrs.name + ".$valid";
var a_input = angular.element($compile('<span style="color:red" ng-show="!' + varName + '" >*</span>')(scope));
element.parent().prepend(a_input);
}
};
});