Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

ngMaxlength attribute as separate reusable directive. #6750

Closed
pluff opened this issue Mar 19, 2014 · 0 comments
Closed

ngMaxlength attribute as separate reusable directive. #6750

pluff opened this issue Mar 19, 2014 · 0 comments

Comments

@pluff
Copy link

pluff commented Mar 19, 2014

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

@lefos987 lefos987 added this to the Backlog milestone Mar 20, 2014
matsko added a commit to matsko/angular.js that referenced this issue May 7, 2014
matsko added a commit to matsko/angular.js that referenced this issue May 7, 2014
matsko added a commit to matsko/angular.js that referenced this issue May 7, 2014
matsko added a commit to matsko/angular.js that referenced this issue May 27, 2014
matsko added a commit to matsko/angular.js that referenced this issue May 27, 2014
matsko added a commit to matsko/angular.js that referenced this issue Jun 10, 2014
matsko added a commit to matsko/angular.js that referenced this issue Jun 10, 2014
matsko added a commit to matsko/angular.js that referenced this issue Jun 10, 2014
matsko added a commit to matsko/angular.js that referenced this issue Jun 10, 2014
@matsko matsko closed this as completed in 26d91b6 Jun 13, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants