| 25104 | * @param {string=} ngList optional delimiter that should be used to split the value. |
| 25105 | */ |
| 25106 | var ngListDirective = function() { |
| 25107 | return { |
| 25108 | restrict: 'A', |
| 25109 | priority: 100, |
| 25110 | require: 'ngModel', |
| 25111 | link: function(scope, element, attr, ctrl) { |
| 25112 | // We want to control whitespace trimming so we use this convoluted approach |
| 25113 | // to access the ngList attribute, which doesn't pre-trim the attribute |
| 25114 | var ngList = element.attr(attr.$attr.ngList) || ', '; |
| 25115 | var trimValues = attr.ngTrim !== 'false'; |
| 25116 | var separator = trimValues ? trim(ngList) : ngList; |
| 25117 | |
| 25118 | var parse = function(viewValue) { |
| 25119 | // If the viewValue is invalid (say required but empty) it will be `undefined` |
| 25120 | if (isUndefined(viewValue)) return; |
| 25121 | |
| 25122 | var list = []; |
| 25123 | |
| 25124 | if (viewValue) { |
| 25125 | forEach(viewValue.split(separator), function(value) { |
| 25126 | if (value) list.push(trimValues ? trim(value) : value); |
| 25127 | }); |
| 25128 | } |
| 25129 | |
| 25130 | return list; |
| 25131 | }; |
| 25132 | |
| 25133 | ctrl.$parsers.push(parse); |
| 25134 | ctrl.$formatters.push(function(value) { |
| 25135 | if (isArray(value)) { |
| 25136 | return value.join(ngList); |
| 25137 | } |
| 25138 | |
| 25139 | return undefined; |
| 25140 | }); |
| 25141 | |
| 25142 | // Override the standard $isEmpty because an empty array means the input is empty. |
| 25143 | ctrl.$isEmpty = function(value) { |
| 25144 | return !value || !value.length; |
| 25145 | }; |
| 25146 | } |
| 25147 | }; |
| 25148 | }; |
| 25149 | |
| 25150 | /* global VALID_CLASS: true, |
| 25151 | INVALID_CLASS: true, |