Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to trigger angular parsers without inputing anything in the field

As the subject states, how do I trigger the actions to take place inside a

modelController.$parsers(...) 

without user input... the only way I can think of is wrapping them inside a function and call it, but is there a better way to trigger

**//pseudo
$(modelController).trigger('just got dirty');**

the reason I would need this is to trigger the input field to validate itself on submitting page.

like image 401
user2167582 Avatar asked Apr 29 '13 17:04

user2167582


1 Answers

I have found a way to solve this - just call the parsers with the model value:

angular.forEach(ngModel.$parsers, function (parser) {
    parser(ngModel.$viewValue);
});

It`s so simple, and it seems to be the most correct solution.

like image 173
Vasiliy Mazhekin Avatar answered Nov 15 '22 06:11

Vasiliy Mazhekin