| 22688 | * @param {string=} ngList optional delimiter that should be used to split the value. |
| 22689 | */ |
| 22690 | var ngListDirective = function() { |
| 22691 | return { |
| 22692 | restrict: 'A', |
| 22693 | priority: 100, |
| 22694 | require: 'ngModel', |
| 22695 | link: function(scope, element, attr, ctrl) { |
| 22696 | // We want to control whitespace trimming so we use this convoluted approach |
| 22697 | // to access the ngList attribute, which doesn't pre-trim the attribute |
| 22698 | var ngList = element.attr(attr.$attr.ngList) || ', '; |
| 22699 | var trimValues = attr.ngTrim !== 'false'; |
| 22700 | var separator = trimValues ? trim(ngList) : ngList; |
| 22701 | |
| 22702 | var parse = function(viewValue) { |
| 22703 | // If the viewValue is invalid (say required but empty) it will be `undefined` |
| 22704 | if (isUndefined(viewValue)) return; |
| 22705 | |
| 22706 | var list = []; |
| 22707 | |
| 22708 | if (viewValue) { |
| 22709 | forEach(viewValue.split(separator), function(value) { |
| 22710 | if (value) list.push(trimValues ? trim(value) : value); |
| 22711 | }); |
| 22712 | } |
| 22713 | |
| 22714 | return list; |
| 22715 | }; |
| 22716 | |
| 22717 | ctrl.$parsers.push(parse); |
| 22718 | ctrl.$formatters.push(function(value) { |
| 22719 | if (isArray(value)) { |
| 22720 | return value.join(ngList); |
| 22721 | } |
| 22722 | |
| 22723 | return undefined; |
| 22724 | }); |
| 22725 | |
| 22726 | // Override the standard $isEmpty because an empty array means the input is empty. |
| 22727 | ctrl.$isEmpty = function(value) { |
| 22728 | return !value || !value.length; |
| 22729 | }; |
| 22730 | } |
| 22731 | }; |
| 22732 | }; |
| 22733 | |
| 22734 | /* global VALID_CLASS: true, |
| 22735 | INVALID_CLASS: true, |