| 21409 | * @param {string=} ngList optional delimiter that should be used to split the value. |
| 21410 | */ |
| 21411 | var ngListDirective = function() { |
| 21412 | return { |
| 21413 | restrict: 'A', |
| 21414 | priority: 100, |
| 21415 | require: 'ngModel', |
| 21416 | link: function(scope, element, attr, ctrl) { |
| 21417 | // We want to control whitespace trimming so we use this convoluted approach |
| 21418 | // to access the ngList attribute, which doesn't pre-trim the attribute |
| 21419 | var ngList = element.attr(attr.$attr.ngList) || ', '; |
| 21420 | var trimValues = attr.ngTrim !== 'false'; |
| 21421 | var separator = trimValues ? trim(ngList) : ngList; |
| 21422 | |
| 21423 | var parse = function(viewValue) { |
| 21424 | // If the viewValue is invalid (say required but empty) it will be `undefined` |
| 21425 | if (isUndefined(viewValue)) return; |
| 21426 | |
| 21427 | var list = []; |
| 21428 | |
| 21429 | if (viewValue) { |
| 21430 | forEach(viewValue.split(separator), function(value) { |
| 21431 | if (value) list.push(trimValues ? trim(value) : value); |
| 21432 | }); |
| 21433 | } |
| 21434 | |
| 21435 | return list; |
| 21436 | }; |
| 21437 | |
| 21438 | ctrl.$parsers.push(parse); |
| 21439 | ctrl.$formatters.push(function(value) { |
| 21440 | if (isArray(value)) { |
| 21441 | return value.join(ngList); |
| 21442 | } |
| 21443 | |
| 21444 | return undefined; |
| 21445 | }); |
| 21446 | |
| 21447 | // Override the standard $isEmpty because an empty array means the input is empty. |
| 21448 | ctrl.$isEmpty = function(value) { |
| 21449 | return !value || !value.length; |
| 21450 | }; |
| 21451 | } |
| 21452 | }; |
| 21453 | }; |
| 21454 | |
| 21455 | |
| 21456 | var CONSTANT_VALUE_REGEXP = /^(true|false|\d+)$/; |