| 28987 | * |
| 28988 | */ |
| 28989 | var ngListDirective = function() { |
| 28990 | return { |
| 28991 | restrict: 'A', |
| 28992 | priority: 100, |
| 28993 | require: 'ngModel', |
| 28994 | link: function(scope, element, attr, ctrl) { |
| 28995 | var ngList = attr.ngList || ', '; |
| 28996 | var trimValues = attr.ngTrim !== 'false'; |
| 28997 | var separator = trimValues ? trim(ngList) : ngList; |
| 28998 | |
| 28999 | var parse = function(viewValue) { |
| 29000 | // If the viewValue is invalid (say required but empty) it will be `undefined` |
| 29001 | if (isUndefined(viewValue)) return; |
| 29002 | |
| 29003 | var list = []; |
| 29004 | |
| 29005 | if (viewValue) { |
| 29006 | forEach(viewValue.split(separator), function(value) { |
| 29007 | if (value) list.push(trimValues ? trim(value) : value); |
| 29008 | }); |
| 29009 | } |
| 29010 | |
| 29011 | return list; |
| 29012 | }; |
| 29013 | |
| 29014 | ctrl.$parsers.push(parse); |
| 29015 | ctrl.$formatters.push(function(value) { |
| 29016 | if (isArray(value)) { |
| 29017 | return value.join(ngList); |
| 29018 | } |
| 29019 | |
| 29020 | return undefined; |
| 29021 | }); |
| 29022 | |
| 29023 | // Override the standard $isEmpty because an empty array means the input is empty. |
| 29024 | ctrl.$isEmpty = function(value) { |
| 29025 | return !value || !value.length; |
| 29026 | }; |
| 29027 | } |
| 29028 | }; |
| 29029 | }; |
| 29030 | |
| 29031 | /* global VALID_CLASS: true, |
| 29032 | INVALID_CLASS: true, |