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.

maxlength directive doesn't work with numbers #8811

Closed

Description

@hon2a

The maxlength directive is broken when used with Number model values in the current Beta. When I try using timepicker from angular-bootstrap, the hours/minutes inputs become invalid as soon as they reach values >= 10. This happens because, for the sake of readability, values < 10 are prefixed with a zero and saved to the model as strings. Values >= 10 are saved as numbers, which makes this offending line in the directive:

return ctrl.$isEmpty(value) || value.length <= maxlength;

fail, as value.length equals to undefined for Numbers. Changing the code to

return ctrl.$isEmpty(value) || String(value).length <= maxlength;

seems to work just fine.


Thanks in advance for the fix.

Activity

  1. Narretz commented on Aug 28, 2014

    @Narretz
    Contributor

    This is a duplicate of #7848

  2. Narretz commented on Aug 28, 2014

    @Narretz
    Contributor

    I'll try to get someone interested in this for the next beta / RC.

  3. caitp commented on Aug 28, 2014

    @caitp
    Contributor

    a fix for this has already been written, it's never been reviewed or merged #7968

  4. Narretz commented on Aug 28, 2014

    @Narretz
    Contributor

    The PR in question is #7968
    I pushed it to the next RC.

  5. added 2 commits that reference this issue on Aug 28, 2014
    7faa60c
    77ce5b8
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions