|
1 | 1 | /*!
|
2 | 2 | * ui-select
|
3 | 3 | * http://github.com/angular-ui/ui-select
|
4 |
| - * Version: 0.14.8 - 2016-02-18T22:01:43.792Z |
| 4 | + * Version: 0.14.10 - 2016-03-09T10:25:24.529Z |
5 | 5 | * License: MIT
|
6 | 6 | */
|
7 | 7 |
|
@@ -113,7 +113,8 @@ var uis = angular.module('ui.select', [])
|
113 | 113 | generateId: function() {
|
114 | 114 | return latestId++;
|
115 | 115 | },
|
116 |
| - appendToBody: false |
| 116 | + appendToBody: false, |
| 117 | + disableBackspaceReset: false |
117 | 118 | })
|
118 | 119 |
|
119 | 120 | // See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913
|
@@ -482,7 +483,11 @@ uis.controller('uiSelectCtrl',
|
482 | 483 | ctrl.setItemsFn(data);
|
483 | 484 | }else{
|
484 | 485 | if ( data !== undefined ) {
|
485 |
| - var filteredItems = data.filter(function(i) {return selectedItems && selectedItems.indexOf(i) < 0;}); |
| 486 | + var filteredItems = data.filter(function(i) { |
| 487 | + return selectedItems.every(function(selectedItem) { |
| 488 | + return !angular.equals(i, selectedItem); |
| 489 | + }); |
| 490 | + }); |
486 | 491 | ctrl.setItemsFn(filteredItems);
|
487 | 492 | }
|
488 | 493 | }
|
@@ -956,6 +961,11 @@ uis.directive('uiSelect',
|
956 | 961 | $select.searchEnabled = searchEnabled !== undefined ? searchEnabled : uiSelectConfig.searchEnabled;
|
957 | 962 | });
|
958 | 963 |
|
| 964 | + scope.$watch('disableBackspaceReset', function() { |
| 965 | + var disableBackspaceReset = scope.$eval(attrs.disableBackspaceReset); |
| 966 | + $select.disableBackspaceReset = disableBackspaceReset !== undefined ? disableBackspaceReset : uiSelectConfig.disableBackspaceReset; |
| 967 | + }); |
| 968 | + |
959 | 969 | scope.$watch('sortable', function() {
|
960 | 970 | var sortable = scope.$eval(attrs.sortable);
|
961 | 971 | $select.sortable = sortable !== undefined ? sortable : uiSelectConfig.sortable;
|
@@ -1580,9 +1590,19 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
|
1580 | 1590 | stashArr = stashArr.slice(1,stashArr.length);
|
1581 | 1591 | }
|
1582 | 1592 | newItem = $select.tagging.fct($select.search);
|
1583 |
| - newItem.isTag = true; |
1584 |
| - // verify the the tag doesn't match the value of an existing item |
1585 |
| - if ( stashArr.filter( function (origItem) { return angular.equals( origItem, $select.tagging.fct($select.search) ); } ).length > 0 ) { |
| 1593 | + // verify the new tag doesn't match the value of a possible selection choice or an already selected item. |
| 1594 | + if ( |
| 1595 | + stashArr.some(function (origItem) { |
| 1596 | + return angular.equals(origItem, $select.tagging.fct($select.search)); |
| 1597 | + }) || |
| 1598 | + $select.selected.some(function (origItem) { |
| 1599 | + return angular.equals(origItem, newItem); |
| 1600 | + }) |
| 1601 | + ) { |
| 1602 | + scope.$evalAsync(function () { |
| 1603 | + $select.activeIndex = 0; |
| 1604 | + $select.items = items; |
| 1605 | + }); |
1586 | 1606 | return;
|
1587 | 1607 | }
|
1588 | 1608 | newItem.isTag = true;
|
@@ -1778,8 +1798,7 @@ uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $comp
|
1778 | 1798 | });
|
1779 | 1799 | });
|
1780 | 1800 | focusser.bind("keydown", function(e){
|
1781 |
| - |
1782 |
| - if (e.which === KEY.BACKSPACE) { |
| 1801 | + if (e.which === KEY.BACKSPACE && $select.disableBackspaceReset === false) { |
1783 | 1802 | e.preventDefault();
|
1784 | 1803 | e.stopPropagation();
|
1785 | 1804 | $select.select(undefined);
|
@@ -1977,38 +1996,48 @@ uis.service('uisRepeatParser', ['uiSelectMinErr','$parse', function(uiSelectMinE
|
1977 | 1996 |
|
1978 | 1997 |
|
1979 | 1998 | var match;
|
1980 |
| - var isObjectCollection = /\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)/.test(expression); |
| 1999 | + //var isObjectCollection = /\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)/.test(expression); |
1981 | 2000 | // If an array is used as collection
|
1982 | 2001 |
|
1983 | 2002 | // if (isObjectCollection){
|
1984 |
| - //00000000000000000000000000000111111111000000000000000222222222222220033333333333333333333330000444444444444444444000000000000000556666660000077777777777755000000000000000000000088888880000000 |
1985 |
| - match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+(([\w\.]+)?\s*(|\s*[\s\S]+?))?(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); |
| 2003 | + // 000000000000000000000000000000111111111000000000000000222222222222220033333333333333333333330000444444444444444444000000000000000055555555555000000000000000000000066666666600000000 |
| 2004 | + match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+(\s*[\s\S]+?)?(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); |
1986 | 2005 |
|
1987 | 2006 | // 1 Alias
|
1988 | 2007 | // 2 Item
|
1989 | 2008 | // 3 Key on (key,value)
|
1990 | 2009 | // 4 Value on (key,value)
|
1991 |
| - // 5 Collection expresion (only used when using an array collection) |
1992 |
| - // 6 Object that will be converted to Array when using (key,value) syntax |
1993 |
| - // 7 Filters that will be applied to #6 when using (key,value) syntax |
1994 |
| - // 8 Track by |
| 2010 | + // 5 Source expression (including filters) |
| 2011 | + // 6 Track by |
1995 | 2012 |
|
1996 | 2013 | if (!match) {
|
1997 | 2014 | throw uiSelectMinErr('iexp', "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",
|
1998 | 2015 | expression);
|
1999 | 2016 | }
|
2000 |
| - if (!match[6] && isObjectCollection) { |
2001 |
| - throw uiSelectMinErr('iexp', "Expected expression in form of '_item_ as (_key_, _item_) in _ObjCollection_ [ track by _id_]' but got '{0}'.", |
2002 |
| - expression); |
| 2017 | + |
| 2018 | + var source = match[5], |
| 2019 | + filters = ''; |
| 2020 | + |
| 2021 | + // When using (key,value) ui-select requires filters to be extracted, since the object |
| 2022 | + // is converted to an array for $select.items |
| 2023 | + // (in which case the filters need to be reapplied) |
| 2024 | + if (match[3]) { |
| 2025 | + // Remove any enclosing parenthesis |
| 2026 | + source = match[5].replace(/(^\()|(\)$)/g, ''); |
| 2027 | + // match all after | but not after || |
| 2028 | + var filterMatch = match[5].match(/^\s*(?:[\s\S]+?)(?:[^\|]|\|\|)+([\s\S]*)\s*$/); |
| 2029 | + if(filterMatch && filterMatch[1].trim()) { |
| 2030 | + filters = filterMatch[1]; |
| 2031 | + source = source.replace(filters, ''); |
| 2032 | + } |
2003 | 2033 | }
|
2004 | 2034 |
|
2005 | 2035 | return {
|
2006 | 2036 | itemName: match[4] || match[2], // (lhs) Left-hand side,
|
2007 | 2037 | keyName: match[3], //for (key, value) syntax
|
2008 |
| - source: $parse(!match[3] ? match[5] : match[6]), |
2009 |
| - sourceName: match[6], |
2010 |
| - filters: match[7], |
2011 |
| - trackByExp: match[8], |
| 2038 | + source: $parse(source), |
| 2039 | + filters: filters, |
| 2040 | + trackByExp: match[6], |
2012 | 2041 | modelMapper: $parse(match[1] || match[4] || match[2]),
|
2013 | 2042 | repeatExpression: function (grouped) {
|
2014 | 2043 | var expression = this.itemName + ' in ' + (grouped ? '$group.items' : '$select.items');
|
|
0 commit comments