0

I'm a beginner with AngularJS and for now I'm trying to create a registration form. I tried to follow the instructions I found on the internet, but it looks like I cannot get my validation triggered. I'm not sure what is wrong.

Here's my JS for the validation:

var login = angular.module('login', []);

login.directive('repeatedValue', function () {
    return {
        require: 'ngModel',
        link: function (scope, elm, attrs, ctrl) {
            ctrl.$validators.repeatedValue = function (modelValue, viewValue) {
                alert("validation");
                return false;
            };
        }
    };
});

and the input field looks like this:

<input type="password" class="form-control" id="password2"
                               placeholder="Repeat password" value="" tabindex="3"  ng-model="login.registerPassword2" repeatedValue/>

still, for some reason, even if I start typing into the field, the validation is not triggered and as a result I can still submit the form.

3
  • 1
    use the repeated-value attribute and let me know Commented Jul 12, 2015 at 14:46
  • this is weird, but works :) thanks Commented Jul 12, 2015 at 14:49
  • this is not weird. It's like angular works :) Commented Jul 12, 2015 at 14:58

1 Answer 1

1

you must use right directive name in template (dash-delimited)

 <input type="password" ... repeated-value/>

See Normalization chapter in docs https://docs.angularjs.org/guide/directive

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

Comments

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.