Skip to content

bug: Angular min/max validation not working on ion-input #23480

Closed

Description

@tn185070

Bug Report

Ionic version:

[ ] 4.x
[x] 5.x

Current behavior:

Angular min/max validation is not working on ion-inputs of type number.

Expected behavior:

min/max validation works on ion-inputs.

Steps to reproduce:

Type a number outside of the allowed range into the input and see that the form is still valid.

Related code:

StackBlitz with regular input and ion-input demonstrating the issue: https://stackblitz.com/edit/ionic-angular-v5-qyn5kf?file=src/app/app.component.html.

Other information:

#20163 and #18240 reported this previously but at that time the issues were closed because it was a bug in Angular. Now Angular has fixed their bug in version 12 (angular/angular#39063) but the validation is still not working for ion-inputs. If I change ion-input to a input then the validation works.

Ionic info:

Ionic:

   Ionic CLI                     : 5.4.16
   Ionic Framework               : @ionic/angular 5.3.1
   @angular-devkit/build-angular : 12.0.0
   @angular-devkit/schematics    : 12.0.0
   @angular/cli                  : 12.0.0
   @ionic/angular-toolkit        : 3.1.1

Capacitor:

   Capacitor CLI   : 2.4.0
   @capacitor/core : 2.4.0

Utility:

   cordova-res : not installed
   native-run  : 1.0.0

System:

   NodeJS : v14.17.0 (C:\Program Files\nodejs\node.exe)
   npm    : 6.11.3
   OS     : Windows 10

Activity

  1. liamdebeasi commented on Jun 22, 2021

    @liamdebeasi
    Contributor

    Thanks for the issue. The problem here appears to be that the min and max validators in Angular look specifically for input[type=number], but we need the validators to see ion-input[type=number], so the max/min validators are never setup on the ion-input components in your test app: https://github.com/angular/angular/blob/master/packages/forms/src/directives/validators.ts#L168

    Other validators, such as https://github.com/angular/angular/blob/master/packages/forms/src/directives/validators.ts#L619, do not have this restriction as they only look for the attributes, allowing them to pick up ion-input.

    One option here is to extend the MaxValidator and MinValidator directives with selectors that allow for ion-input, but I am trying to understand why these new validators are restricted to only input while other validators such as maxlength are not, despite maxlength only being available for input and textarea. I reached out to the Angular team for clarification, so hopefully we should have an idea as to how to solve this issue soon.

  2. added
    type: bug
    on Jun 22, 2021
  3. liamdebeasi commented on Jul 6, 2021

    @liamdebeasi
    Contributor

    I touched based with the Angular team and it looks like this change was done so as to not conflict with 3rd party libraries that have their own max/min validators. I think extending the validators with a custom selector for ion-input seems like to best option here.

  4. added
    package: angular
    on Jul 6, 2021
  5. added
    type: bug
    and removed
    type: bug
    on Dec 1, 2021
  6. JulienLecoq commented on Jan 21, 2023

    @JulienLecoq

    Any news about this issue?

  7. added a commit that references this issue on Aug 18, 2023
    77707b8
  8. ionitron-bot commented on Sep 17, 2023

    @ionitron-bot

    Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

  9. locked and limited conversation to collaborators on Sep 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: angulartype: bug

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions