Skip to content

bug: ion-input type="number" max and min attribute validation does not work #20163

Closed

Description

@shamohai

The latest version of ionic 4, ion-input type="number", max and min attribute form validation does not work.

type="date" max and min attribute form validation is success, it works fine.

Activity

  1. liamdebeasi commented on Jan 8, 2020

    @liamdebeasi
    Contributor

    Thanks for the issue. Can you provide a repo with the code required to reproduce this issue?

  2. added
    needs: reply
    on Jan 8, 2020
  3. shamohai commented on Jan 9, 2020

    @shamohai
    Author

    ionic 4 angular

    I don't have a code repo.
    The code cannot be displayed, I cut some pictures.

    html:
    QQ图片20200109095844

    `

    Form Validation: {{ngForm.valid}} Quantity: `

    min: 2, max: 5, normally it should be a number between [2,5].

    QQ图片20200109095330

    The actual situation is this.

    QQ图片20200109095504

    Seems to only verify the must, not verify min and max.

  4. added and removed
    needs: reply
    on Jan 9, 2020
  5. tahaerden commented on Jan 9, 2020

    @tahaerden

    I can confirm the issue.
    For text inputs, minlength, maxlength, required etc. works.
    For number inputs, required still works. min/max doesn't.

    Here is my form html:

    `

        <form #f="ngForm" (ngSubmit)="createEmployee(f)">
          <ion-list lines="full" class="ion-no-margin ion-no-padding">
            <ion-item>
              <ion-label position="stacked"
                >Name <ion-text color="danger">*</ion-text></ion-label
              >
              <ion-input
                required
                minlength="2"
                type="text"
                ngModel
                name="name"
              ></ion-input>
            </ion-item>
    
            <ion-item>
              <ion-label position="stacked"
                >Salary <ion-text color="danger">*</ion-text></ion-label
              >
              <ion-input required type="text" ngModel name="salary"></ion-input>
            </ion-item>
    
            <ion-item>
              <ion-label position="stacked"
                >Age <ion-text color="danger">*</ion-text></ion-label
              >
              <ion-input
                required
                min="18"
                max="65"
                type="number"
                ngModel
                name="age"
              ></ion-input>
            </ion-item>
    
            <ion-item>
              <ion-label position="stacked">Avatar</ion-label>
              <ion-input type="text" ngModel name="profile_image"></ion-input>
            </ion-item>
          </ion-list>
          <div class="ion-padding">
            <ion-button
              expand="block"
              type="submit"
              class="ion-no-margin"
              [disabled]="!f.form.valid"
              >Create Employee</ion-button
            >
          </div>
        </form>
    

    `

  6. tahaerden commented on Jan 31, 2020

    @tahaerden

    Any update on this @liamdebeasi ?

  7. blended-ideas commented on Feb 26, 2020

    @blended-ideas

    This is a major issue. Can we get any updates on this?

  8. liamdebeasi commented on Feb 26, 2020

    @liamdebeasi
    Contributor

    Thanks for the follow up. I am going to close this as this is not a bug in Ionic Framework. min/max validation for number inputs does not appear to be working for template driven forms in Angular: angular/angular#16352.

    I have created an example here showing the same behavior using an Angular app without Ionic Framework: https://stackblitz.com/edit/angular-input-min-max?file=src/app/app.component.html

  9. ionitron-bot commented on Mar 27, 2020

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

  10. locked and limited conversation to collaborators on Mar 27, 2020
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

    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