| 30055 | * |
| 30056 | */ |
| 30057 | var ngListDirective = function() { |
| 30058 | return { |
| 30059 | restrict: 'A', |
| 30060 | priority: 100, |
| 30061 | require: 'ngModel', |
| 30062 | link: function(scope, element, attr, ctrl) { |
| 30063 | var ngList = attr.ngList || ', '; |
| 30064 | var trimValues = attr.ngTrim !== 'false'; |
| 30065 | var separator = trimValues ? trim(ngList) : ngList; |
| 30066 | |
| 30067 | var parse = function(viewValue) { |
| 30068 | // If the viewValue is invalid (say required but empty) it will be `undefined` |
| 30069 | if (isUndefined(viewValue)) return; |
| 30070 | |
| 30071 | var list = []; |
| 30072 | |
| 30073 | if (viewValue) { |
| 30074 | forEach(viewValue.split(separator), function(value) { |
| 30075 | if (value) list.push(trimValues ? trim(value) : value); |
| 30076 | }); |
| 30077 | } |
| 30078 | |
| 30079 | return list; |
| 30080 | }; |
| 30081 | |
| 30082 | ctrl.$parsers.push(parse); |
| 30083 | ctrl.$formatters.push(function(value) { |
| 30084 | if (isArray(value)) { |
| 30085 | return value.join(ngList); |
| 30086 | } |
| 30087 | |
| 30088 | return undefined; |
| 30089 | }); |
| 30090 | |
| 30091 | // Override the standard $isEmpty because an empty array means the input is empty. |
| 30092 | ctrl.$isEmpty = function(value) { |
| 30093 | return !value || !value.length; |
| 30094 | }; |
| 30095 | } |
| 30096 | }; |
| 30097 | }; |
| 30098 | |
| 30099 | /* global VALID_CLASS: true, |
| 30100 | INVALID_CLASS: true, |