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.

ngMaxlength attribute as separate reusable directive. #6750

Closed

Description

@pluff

Currently ngMaxlength validation can be applied to inputs only, so can't be applied to custom controls. So if I want to use it with ngModel without input field I have to write custom 100% duplicated separate directive and use it. It would be great to have this validator to be applicable to anything that has ngModel attached, not only inputs.

Same applies to ngMinlength etc.

Example directive I have to write:

app.directive 'myMaxlength', ->
  {
    restrict: 'A',
    require: 'ngModel',
    link: (scope, el, attrs, ctrl) ->
      maxlength = parseInt(attrs.myMaxlength);
      validator = (value) ->
        if ctrl.$isEmpty(value) || value.length <= maxlength
          ctrl.$setValidity 'maxlength', true
          value
        else
          ctrl.$setValidity 'maxlength', false
          undefined
      ctrl.$formatters.push validator
      ctrl.$parsers.push validator
  }

which almost fully duplicates https://github.com/angular/angular.js/blob/master/src/ng/directive/input.js#L1009-L1018

Activity

  1. added this to the milestone on Mar 20, 2014
  2. added 3 commits that reference this issue on May 7, 2014
    3407627
    14f176e
    f329004
  3. added 2 commits that reference this issue on May 27, 2014
    47a1d27
    5cb104b
  4. added 4 commits that reference this issue on Jun 10, 2014
    ccba701
    b2ecb65
    865f8d5
    c15d827
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions