Skip to content

ngModel min validator seems ignored #17080

Closed

Description

@SanderElias

I'm submitting a ... (check one with "x")

[x ] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
When an input element has a min value on it, it seems this validator is ignored.

<input #m="ngModel" name='price'  type="number" required [(ngModel)]="price" step="0.05" min="0.95">

if you focus and tab out without setting a minimum value of 0.95 it's still valid when it should not be.

Expected behavior
The validator should not be true if the minimum value is not reached.

Minimal reproduction of the problem with instructions

here is a plunk that demonstrates this behaviour

What is the motivation / use case for changing the behavior?
validations should be enforced.

  • Angular version: 4.2.x

Activity

  1. SteveVanOpstal commented on May 29, 2017

    @SteveVanOpstal

    Only four Validator directives exist:

    • required
    • minlength
    • maxlength
    • pattern

    So a min validator should be made with a custom implementation of Validator.

    You can make it yourself: https://stackoverflow.com/a/39848327/531122

    Or use a library (like https://github.com/yuyang041060120/ng2-validation) to do it for you.

    Although it is marked as experimental, documentation is lacking on this.

  2. SanderElias commented on May 29, 2017

    @SanderElias
    ContributorAuthor
  3. SteveVanOpstal commented on May 29, 2017

    @SteveVanOpstal

    The Plunker got me confused as it is loading Angular 4.1.3. I modified the Plunker to version 4.2.0-rc.1 and I am debugging it now. It could have something to do with MinValidator using ParseInt (See https://github.com/angular/angular/blob/4.2.0-rc.1/packages/forms/src/directives/validators.ts#L133).

  4. SteveVanOpstal commented on May 29, 2017

    @SteveVanOpstal

    ParseInt seems to be the issue, as it converts the string '0.95' into number 0

  5. SanderElias commented on May 29, 2017

    @SanderElias
    ContributorAuthor

    @SteveVanOpstal Yeah, I think that is indeed the issue.
    the validator itself should be doing the right thing. I was looking at the wrong spot! good catch!

  6. SteveVanOpstal commented on May 29, 2017

    @SteveVanOpstal

    I'm working on a fix and will create a pull request of it

  7. Toxicable commented on May 30, 2017

    @Toxicable

    @SteveVanOpstal Thanks for pointing that out, I do apologize for my mistake, I remember seeing this when I was making the validator since it was half copy pasted from another old PR (which specifically included this part) I am unsure why I did not change it then, I thought I had.
    Anyway, sorry for any inconvenience this has caused

  8. SteveVanOpstal commented on May 30, 2017

    @SteveVanOpstal

    @Toxicable Not a problem, it is fixed now.

  9. angular-automatic-lock-bot commented on Sep 13, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  10. locked and limited conversation to collaborators on Sep 13, 2019
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

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions