You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Feature request: Ability to read trigger event for $parsers. #8976
Currently when an input directive fires a view value change it calls $setViewValue. This method has a second parameter trigger that could be optionally passed to the $parsers pipeline. This could be really useful when you use autocomplete features inside a $parser on blur but you want the model to validate on keyup, etc.
We've got ngModelOptions: {updateOn: 'default blur'} that allows us to trigger the parsers and validators in two different scenarios.
We also have the trigger parameter on $setViewValue.
We just need passing trigger to the $parsers pipeline.
Hm, ideally the $parsers should only be concerned with transforming the $viewValue into the $modelValue. What you describes sounds like you are 'abusing' it for something else. Can you describe your setup a little?
Okay, let's say I have a number directive that does the following;
Checks if the viewValue is a valid number.
Checks if the number is between range.
Adds decimal places and thousand commas (viewValue)
Rounds on X number of digits (model and viewValue).
In my parser then, I would like to do rounding and decimal placing on 'blur' but I would like the validation to keep happening while typing. I can do ngModelOptions: {updateOn: 'default blur'} so blur and keyup, etc trigger my parsers and validators. But I have no way of telling which event triggered the $parser to know if the user has finished inputting a field ('blur' event triggered).
My parsers do:
Checks if it's a valid number when trying to parse the string (will return undefined if it's unparsable, which as of 1.3-beta.rc0 adds validation error 'parse').
Adds decimal places and thousand commas (viewValue)
Rounds on X number of digits (modelValue and viewValue).
And my validators do: Checks if the viewValue is a valid number.
Checks if the number is between range.
I'm with @Narretz and think that you are trying to do too much in your parser. I suggest that you create an directive that will listen on blur and do the extra processing when the event fires.
Activity
Narretz commentedon Sep 8, 2014
Hm, ideally the $parsers should only be concerned with transforming the $viewValue into the $modelValue. What you describes sounds like you are 'abusing' it for something else. Can you describe your setup a little?
wawyed commentedon Sep 8, 2014
Okay, let's say I have a number directive that does the following;
Checks if the viewValue is a valid number.
Checks if the number is between range.
Adds decimal places and thousand commas (viewValue)
Rounds on X number of digits (model and viewValue).
In my parser then, I would like to do rounding and decimal placing on 'blur' but I would like the validation to keep happening while typing. I can do
ngModelOptions: {updateOn: 'default blur'}so blur and keyup, etc trigger my parsers and validators. But I have no way of telling which event triggered the$parserto know if the user has finished inputting a field ('blur' event triggered).Narretz commentedon Sep 8, 2014
That's pretty interesting. Do the parsers do all that, parsing, validation, modifying the viewValue? And do you use angular 1.3 or 1.2?
wawyed commentedon Sep 8, 2014
I'm using angular 1.3-beta.rc0
My parsers do:
Checks if it's a valid number when trying to parse the string (will return undefined if it's unparsable, which as of 1.3-beta.rc0 adds validation error 'parse').
Adds decimal places and thousand commas (viewValue)
Rounds on X number of digits (modelValue and viewValue).
And my validators do:
Checks if the viewValue is a valid number.Checks if the number is between range.
IgorMinar commentedon Oct 2, 2014
I was going to suggest that you use
window.eventbut that's non-standard and doesn't work in FF. :-/IgorMinar commentedon Oct 2, 2014
I'm with @Narretz and think that you are trying to do too much in your parser. I suggest that you create an directive that will listen on blur and do the extra processing when the event fires.