Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
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

Closed

Description

@wawyed

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?

Activity

  1. Narretz commented on Sep 8, 2014

    @Narretz
    Contributor

    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?

  2. added this to the Ice Box milestone on Sep 8, 2014
  3. wawyed commented on Sep 8, 2014

    @wawyed
    Author

    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).

  4. Narretz commented on Sep 8, 2014

    @Narretz
    Contributor

    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?

  5. wawyed commented on Sep 8, 2014

    @wawyed
    Author

    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.

  6. IgorMinar commented on Oct 2, 2014

    @IgorMinar
    Contributor

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

  7. IgorMinar commented on Oct 2, 2014

    @IgorMinar
    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions