0

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);
    }
  };
});
1
  • I haven't tested this but have you tried attr.$set('ngMinlength',100); Commented Sep 18, 2013 at 13:17

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

thanks! any idea why the form is valid when the input field is empty ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.