Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
68
rated 0 times [  74] [ 6]  / answers: 1 / hits: 20946  / 10 Years ago, fri, april 25, 2014, 12:00:00

I'm trying to setup an input, such that when length == 5, it will automatically trigger a blur event. How can I do this?



This is pretty much the concept:



        <input type=tel placeholder=type here. maxlength=5 name=digits ng-model=digits ng-change=if (digits.length ==5) { TRIGGER BLUR};>


Thanks


More From » angularjs

 Answers
47

Here is a basic directive that should get you what you are looking for:



app.directive('lengthChecker', function() {
return function(scope, element, attributes) {
scope.$watch(attributes.lengthChecker, function(newVal, oldVal) {
if (newVal.length >= 5) element[0].blur();
});
};
});


Html:



<input ng-model=digits length-checker=digits/>

[#71299] Thursday, April 24, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
matteo

Total Points: 81
Total Questions: 100
Total Answers: 96

Location: Honduras
Member since Sat, Jul 24, 2021
3 Years ago
;