Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Feature request: Ability to read trigger event for $parsers. #8976

Closed
wawyed opened this issue Sep 8, 2014 · 6 comments
Closed

Feature request: Ability to read trigger event for $parsers. #8976

wawyed opened this issue Sep 8, 2014 · 6 comments

Comments

@wawyed
Copy link

wawyed commented Sep 8, 2014

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.

What do you guys think?

@Narretz
Copy link
Contributor

Narretz commented 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
Copy link
Author

wawyed commented 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 $parser to know if the user has finished inputting a field ('blur' event triggered).

@Narretz
Copy link
Contributor

Narretz commented 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
Copy link
Author

wawyed commented 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
Copy link
Contributor

I was going to suggest that you use window.event but that's non-standard and doesn't work in FF. :-/

@IgorMinar
Copy link
Contributor

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants