| 29095 | * |
| 29096 | */ |
| 29097 | var ngListDirective = function() { |
| 29098 | return { |
| 29099 | restrict: 'A', |
| 29100 | priority: 100, |
| 29101 | require: 'ngModel', |
| 29102 | link: function(scope, element, attr, ctrl) { |
| 29103 | var ngList = attr.ngList || ', '; |
| 29104 | var trimValues = attr.ngTrim !== 'false'; |
| 29105 | var separator = trimValues ? trim(ngList) : ngList; |
| 29106 | |
| 29107 | var parse = function(viewValue) { |
| 29108 | // If the viewValue is invalid (say required but empty) it will be `undefined` |
| 29109 | if (isUndefined(viewValue)) return; |
| 29110 | |
| 29111 | var list = []; |
| 29112 | |
| 29113 | if (viewValue) { |
| 29114 | forEach(viewValue.split(separator), function(value) { |
| 29115 | if (value) list.push(trimValues ? trim(value) : value); |
| 29116 | }); |
| 29117 | } |
| 29118 | |
| 29119 | return list; |
| 29120 | }; |
| 29121 | |
| 29122 | ctrl.$parsers.push(parse); |
| 29123 | ctrl.$formatters.push(function(value) { |
| 29124 | if (isArray(value)) { |
| 29125 | return value.join(ngList); |
| 29126 | } |
| 29127 | |
| 29128 | return undefined; |
| 29129 | }); |
| 29130 | |
| 29131 | // Override the standard $isEmpty because an empty array means the input is empty. |
| 29132 | ctrl.$isEmpty = function(value) { |
| 29133 | return !value || !value.length; |
| 29134 | }; |
| 29135 | } |
| 29136 | }; |
| 29137 | }; |
| 29138 | |
| 29139 | /* global VALID_CLASS: true, |
| 29140 | INVALID_CLASS: true, |