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.

ctrl.$validate(); and custom formatters do not play well toghether in 1.3.x and can lead to side effects #10025

Closed

Description

@AGiorgetti

The thing goes like this:

  • I have a directive with a custom formatter (a custom datetime control) that alters the value in the model in some way for display purposes (datetime object formatted using a mask, something like: dd/mm/yyyy hh:mm, you will of course loose precision)
  • so you have: $modelValue with the original datetime (precision up to milliseconds) and $viewValue with the modified value (precision up to minutes).

if you place any directive/attribute that internally invoke ctrl.$validate() (like the ngRequired) this will have the side effect of parsing the value again and ASSIGN it to the model, OVERWRITING the original value even if the user didn't typed or interacted with anything.

Personally I do think this kind of side-effects are dangerous, something that does a validation should not change my model value.

To my knowledge this wasn't happening in 1.2.x.

Activity

  1. Narretz commented on Nov 12, 2014

    @Narretz
    Contributor

    I answered you comment in the other thread; can you please provide a reproduction of this issue? It seem to differ slightly from the other issues.

  2. added this to the Purgatory milestone on Nov 12, 2014
  3. AGiorgetti commented on Nov 12, 2014

    @AGiorgetti
    Author

    Hi, here's a plunker that reproduce my issue:

    http://plnkr.co/edit/xUppA8

    you can switch to angular 1.2.x and see that the side effect is not there.

    have fun :)

  4. modified the milestones: , Purgatory on Nov 12, 2014
  5. self-assigned this
    on Nov 12, 2014
  6. added 6 commits that reference this issue on Nov 13, 2014
    50f7e66
    2182f8e
    dab714d
    3ffeeb6
    ee27815
    e3764e3
  7. Narretz commented on Nov 25, 2014

    @Narretz
    Contributor

    This is fixed in 1.3.4 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions