Gabor Dolla
Gabor Dolla

Reputation: 2736

switch on angularjs validation from directive

the standard angularjs validation just works:

<form name="myForm"><input name="name" ng-model="name" ng-minlength="10"/></form>

but I can not turn it on from my directive:

<form name="myForm"><input name="name" ng-model="c.name" dynval /></form>

.directive('dynval', function () {
  return {
    require: 'ngModel',
    link: function ($scope, element, attr, ctrl) {
      attr.$set('ng-minlength', 100);
    }
  };
});

Upvotes: 0

Views: 99

Answers (1)

Jesus Rodriguez
Jesus Rodriguez

Reputation: 12018

Two things.

One: you need to set it using camelCase, attr.$set('ngMinlength', 100);

Second: Since you're modifying the element, do it on the compile function.

Here is a live plunk

Upvotes: 1

Related Questions