| 25547 | * @param {string=} ngList optional delimiter that should be used to split the value. |
| 25548 | */ |
| 25549 | var ngListDirective = function() { |
| 25550 | return { |
| 25551 | restrict: 'A', |
| 25552 | priority: 100, |
| 25553 | require: 'ngModel', |
| 25554 | link: function(scope, element, attr, ctrl) { |
| 25555 | // We want to control whitespace trimming so we use this convoluted approach |
| 25556 | // to access the ngList attribute, which doesn't pre-trim the attribute |
| 25557 | var ngList = element.attr(attr.$attr.ngList) || ', '; |
| 25558 | var trimValues = attr.ngTrim !== 'false'; |
| 25559 | var separator = trimValues ? trim(ngList) : ngList; |
| 25560 | |
| 25561 | var parse = function(viewValue) { |
| 25562 | // If the viewValue is invalid (say required but empty) it will be `undefined` |
| 25563 | if (isUndefined(viewValue)) return; |
| 25564 | |
| 25565 | var list = []; |
| 25566 | |
| 25567 | if (viewValue) { |
| 25568 | forEach(viewValue.split(separator), function(value) { |
| 25569 | if (value) list.push(trimValues ? trim(value) : value); |
| 25570 | }); |
| 25571 | } |
| 25572 | |
| 25573 | return list; |
| 25574 | }; |
| 25575 | |
| 25576 | ctrl.$parsers.push(parse); |
| 25577 | ctrl.$formatters.push(function(value) { |
| 25578 | if (isArray(value)) { |
| 25579 | return value.join(ngList); |
| 25580 | } |
| 25581 | |
| 25582 | return undefined; |
| 25583 | }); |
| 25584 | |
| 25585 | // Override the standard $isEmpty because an empty array means the input is empty. |
| 25586 | ctrl.$isEmpty = function(value) { |
| 25587 | return !value || !value.length; |
| 25588 | }; |
| 25589 | } |
| 25590 | }; |
| 25591 | }; |
| 25592 | |
| 25593 | /* global VALID_CLASS: true, |
| 25594 | INVALID_CLASS: true, |