From f597603c1a68bde5cb01f2366378eea0288e36dc Mon Sep 17 00:00:00 2001 From: perymimon Date: Tue, 18 Nov 2014 17:33:20 +0200 Subject: [PATCH 1/6] Update select.js --- src/select.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/select.js b/src/select.js index 95ba2bbb9..0ce7ba99d 100644 --- a/src/select.js +++ b/src/select.js @@ -662,7 +662,7 @@ for (var p = list.length - 1; p >= 0; p--) { locals[$select.parserResult.itemName] = list[p]; result = $select.parserResult.modelMapper(scope, locals); - if (result == value){ + if (angular.equals(result,value)){ resultMultiple.unshift(list[p]); return true; } From 66aa5ea52c986f9c02a2a5b9322cef04f586f8e4 Mon Sep 17 00:00:00 2001 From: perymimon Date: Tue, 18 Nov 2014 18:32:32 +0200 Subject: [PATCH 2/6] Update select.js --- dist/select.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/select.js b/dist/select.js index 3afe26f55..9b9491178 100755 --- a/dist/select.js +++ b/dist/select.js @@ -648,7 +648,7 @@ for (var p = list.length - 1; p >= 0; p--) { locals[$select.parserResult.itemName] = list[p]; result = $select.parserResult.modelMapper(scope, locals); - if (result == value){ + if (angular.equals(result,value)){ resultMultiple.unshift(list[p]); return true; } @@ -981,4 +981,4 @@ $templateCache.put("select2/select-multiple.tpl.html","
"); $templateCache.put("selectize/choices.tpl.html","
{{$group.name}}
"); $templateCache.put("selectize/match.tpl.html","
"); -$templateCache.put("selectize/select.tpl.html","
");}]); \ No newline at end of file +$templateCache.put("selectize/select.tpl.html","
");}]); From 1d39a25cff36bd627d00f3bf09f6414e9a9f4021 Mon Sep 17 00:00:00 2001 From: perymimon Date: Mon, 24 Nov 2014 13:50:15 +0200 Subject: [PATCH 3/6] $select.selected = []; to ngModel.$viewValue =[] since there is no sense to init $select.selected and 3 line latter override it with 'ngModel.$viewValue' --- src/select.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/select.js b/src/select.js index 0ce7ba99d..38377972d 100644 --- a/src/select.js +++ b/src/select.js @@ -807,7 +807,7 @@ if(!angular.isArray(ngModel.$viewValue)){ // Have tolerance for null or undefined values if(angular.isUndefined(ngModel.$viewValue) || ngModel.$viewValue === null){ - $select.selected = []; + ngModel.$viewValue = []; } else { throw uiSelectMinErr('multiarr', "Expected model value to be array but got '{0}'", ngModel.$viewValue); } From 02170698369c53878acb996da53251337a747cd4 Mon Sep 17 00:00:00 2001 From: perymimon Date: Mon, 24 Nov 2014 19:33:22 +0200 Subject: [PATCH 4/6] check in model->value data is not empty since if data=[] is empty when we check for match we got view empty --- src/select.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/select.js b/src/select.js index 38377972d..18a4a3cf4 100644 --- a/src/select.js +++ b/src/select.js @@ -654,7 +654,7 @@ var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search locals = {}, result; - if (data){ + if (data && data.length){ if ($select.multiple){ var resultMultiple = []; var checkFnMultiple = function(list, value){ From 5eaefdbfbf3cdf92e807c62dc14888776509439f Mon Sep 17 00:00:00 2001 From: perymimon Date: Wed, 26 Nov 2014 10:42:43 +0200 Subject: [PATCH 5/6] Update select.js --- dist/select.js | 61 ++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/dist/select.js b/dist/select.js index 9b9491178..18a4a3cf4 100755 --- a/dist/select.js +++ b/dist/select.js @@ -1,11 +1,3 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-14T18:22:05.432Z - * License: MIT - */ - - (function () { "use strict"; @@ -145,8 +137,8 @@ * put as much logic in the controller (instead of the link functions) as possible so it can be easily tested. */ .controller('uiSelectCtrl', - ['$scope', '$element', '$timeout', 'RepeatParser', 'uiSelectMinErr', - function($scope, $element, $timeout, RepeatParser, uiSelectMinErr) { + ['$scope', '$element', '$timeout', 'RepeatParser', 'uiSelectMinErr', 'uiSelectConfig', + function($scope, $element, $timeout, RepeatParser, uiSelectMinErr, uiSelectConfig) { var ctrl = this; @@ -167,6 +159,7 @@ ctrl.refreshDelay = undefined; // Initialized inside uiSelectChoices directive link function ctrl.multiple = false; // Initialized inside uiSelect directive link function ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelect directive link function + ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelect directive link function ctrl.isEmpty = function() { return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === ''; @@ -179,7 +172,7 @@ // Most of the time the user does not want to empty the search input when in typeahead mode function _resetSearchInput() { - if (ctrl.resetSearchInput) { + if (ctrl.resetSearchInput || (ctrl.resetSearchInput === undefined && uiSelectConfig.resetSearchInput)) { ctrl.search = EMPTY_SEARCH; //reset activeIndex if (ctrl.selected && ctrl.items.length && !ctrl.multiple) { @@ -312,7 +305,13 @@ }; ctrl.isActive = function(itemScope) { - return ctrl.open && ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex; + var isActive = ctrl.open && ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex; + + if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { + itemScope.$eval(ctrl.onHighlightCallback); + } + + return isActive; }; ctrl.isDisabled = function(itemScope) { @@ -374,9 +373,24 @@ e.stopPropagation(); }; + ctrl.isLocked = function(itemScope, itemIndex) { + var isLocked, item = ctrl.selected[itemIndex]; + + if (item && !angular.isUndefined(ctrl.lockChoiceExpression)) { + isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); // force the boolean value + item._uiSelectChoiceLocked = isLocked; // store this for later reference + } + + return isLocked; + }; + // Remove item from multiple select ctrl.removeChoice = function(index){ var removedChoice = ctrl.selected[index]; + + // if the choice is locked, can't remove it + if(removedChoice._uiSelectChoiceLocked) return; + var locals = {}; locals[ctrl.parserResult.itemName] = removedChoice; @@ -640,7 +654,7 @@ var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search locals = {}, result; - if (data){ + if (data && data.length){ if ($select.multiple){ var resultMultiple = []; var checkFnMultiple = function(list, value){ @@ -756,7 +770,7 @@ scope.$watch('searchEnabled', function() { var searchEnabled = scope.$eval(attrs.searchEnabled); - $select.searchEnabled = searchEnabled !== undefined ? searchEnabled : true; + $select.searchEnabled = searchEnabled !== undefined ? searchEnabled : uiSelectConfig.searchEnabled; }); attrs.$observe('disabled', function() { @@ -793,7 +807,7 @@ if(!angular.isArray(ngModel.$viewValue)){ // Have tolerance for null or undefined values if(angular.isUndefined(ngModel.$viewValue) || ngModel.$viewValue === null){ - $select.selected = []; + ngModel.$viewValue = []; } else { throw uiSelectMinErr('multiarr', "Expected model value to be array but got '{0}'", ngModel.$viewValue); } @@ -880,6 +894,7 @@ $select.parseRepeatAttr(attrs.repeat, groupByExp); //Result ready at $select.parserResult $select.disableChoiceExpression = attrs.uiDisableChoice; + $select.onHighlightCallback = attrs.onHighlight; if(groupByExp) { var groups = element.querySelectorAll('.ui-select-choices-group'); @@ -893,6 +908,7 @@ } choices.attr('ng-repeat', RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', $select.parserResult.trackByExp, groupByExp)) + .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed .attr('ng-mouseenter', '$select.setActiveItem('+$select.parserResult.itemName +')') .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ')'); @@ -940,6 +956,7 @@ return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html'); }, link: function(scope, element, attrs, $select) { + $select.lockChoiceExpression = attrs.uiLockChoice; attrs.$observe('placeholder', function(placeholder) { $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; }); @@ -968,17 +985,3 @@ }; }); }()); - -angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("bootstrap/choices.tpl.html","
    0\">
  • 0\">
    {{$group.name}}
"); -$templateCache.put("bootstrap/match-multiple.tpl.html"," × "); -$templateCache.put("bootstrap/match.tpl.html",""); -$templateCache.put("bootstrap/select-multiple.tpl.html","
"); -$templateCache.put("bootstrap/select.tpl.html","
"); -$templateCache.put("select2/choices.tpl.html","
  • {{$group.name}}
"); -$templateCache.put("select2/match-multiple.tpl.html","
  • "); -$templateCache.put("select2/match.tpl.html","{{$select.placeholder}} "); -$templateCache.put("select2/select-multiple.tpl.html","
    "); -$templateCache.put("select2/select.tpl.html","
    "); -$templateCache.put("selectize/choices.tpl.html","
    {{$group.name}}
    "); -$templateCache.put("selectize/match.tpl.html","
    "); -$templateCache.put("selectize/select.tpl.html","
    ");}]); From 65fbc9376ae96a24a56048a4b81340231166e49c Mon Sep 17 00:00:00 2001 From: perymimon Date: Thu, 27 Nov 2014 16:48:26 +0200 Subject: [PATCH 6/6] some revert for local development (LTV) --- dist/select.js | 63 +++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/dist/select.js b/dist/select.js index 18a4a3cf4..93674b8b2 100755 --- a/dist/select.js +++ b/dist/select.js @@ -1,3 +1,11 @@ +/*! + * ui-select + * http://github.com/angular-ui/ui-select + * Version: 0.8.3 - 2014-10-14T18:22:05.432Z + * License: MIT + */ + + (function () { "use strict"; @@ -137,8 +145,8 @@ * put as much logic in the controller (instead of the link functions) as possible so it can be easily tested. */ .controller('uiSelectCtrl', - ['$scope', '$element', '$timeout', 'RepeatParser', 'uiSelectMinErr', 'uiSelectConfig', - function($scope, $element, $timeout, RepeatParser, uiSelectMinErr, uiSelectConfig) { + ['$scope', '$element', '$timeout', 'RepeatParser', 'uiSelectMinErr', + function($scope, $element, $timeout, RepeatParser, uiSelectMinErr) { var ctrl = this; @@ -159,7 +167,6 @@ ctrl.refreshDelay = undefined; // Initialized inside uiSelectChoices directive link function ctrl.multiple = false; // Initialized inside uiSelect directive link function ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelect directive link function - ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelect directive link function ctrl.isEmpty = function() { return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === ''; @@ -172,7 +179,7 @@ // Most of the time the user does not want to empty the search input when in typeahead mode function _resetSearchInput() { - if (ctrl.resetSearchInput || (ctrl.resetSearchInput === undefined && uiSelectConfig.resetSearchInput)) { + if (ctrl.resetSearchInput) { ctrl.search = EMPTY_SEARCH; //reset activeIndex if (ctrl.selected && ctrl.items.length && !ctrl.multiple) { @@ -305,13 +312,7 @@ }; ctrl.isActive = function(itemScope) { - var isActive = ctrl.open && ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex; - - if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { - itemScope.$eval(ctrl.onHighlightCallback); - } - - return isActive; + return ctrl.open && ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex; }; ctrl.isDisabled = function(itemScope) { @@ -373,24 +374,9 @@ e.stopPropagation(); }; - ctrl.isLocked = function(itemScope, itemIndex) { - var isLocked, item = ctrl.selected[itemIndex]; - - if (item && !angular.isUndefined(ctrl.lockChoiceExpression)) { - isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); // force the boolean value - item._uiSelectChoiceLocked = isLocked; // store this for later reference - } - - return isLocked; - }; - // Remove item from multiple select ctrl.removeChoice = function(index){ var removedChoice = ctrl.selected[index]; - - // if the choice is locked, can't remove it - if(removedChoice._uiSelectChoiceLocked) return; - var locals = {}; locals[ctrl.parserResult.itemName] = removedChoice; @@ -654,7 +640,9 @@ var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search locals = {}, result; - if (data && data.length){ + if (data && + + data.length){ if ($select.multiple){ var resultMultiple = []; var checkFnMultiple = function(list, value){ @@ -770,7 +758,7 @@ scope.$watch('searchEnabled', function() { var searchEnabled = scope.$eval(attrs.searchEnabled); - $select.searchEnabled = searchEnabled !== undefined ? searchEnabled : uiSelectConfig.searchEnabled; + $select.searchEnabled = searchEnabled !== undefined ? searchEnabled : true; }); attrs.$observe('disabled', function() { @@ -814,6 +802,8 @@ } } $select.selected = ngModel.$viewValue; + + }; function onDocumentClick(e) { @@ -894,7 +884,6 @@ $select.parseRepeatAttr(attrs.repeat, groupByExp); //Result ready at $select.parserResult $select.disableChoiceExpression = attrs.uiDisableChoice; - $select.onHighlightCallback = attrs.onHighlight; if(groupByExp) { var groups = element.querySelectorAll('.ui-select-choices-group'); @@ -908,7 +897,6 @@ } choices.attr('ng-repeat', RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', $select.parserResult.trackByExp, groupByExp)) - .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed .attr('ng-mouseenter', '$select.setActiveItem('+$select.parserResult.itemName +')') .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ')'); @@ -956,7 +944,6 @@ return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html'); }, link: function(scope, element, attrs, $select) { - $select.lockChoiceExpression = attrs.uiLockChoice; attrs.$observe('placeholder', function(placeholder) { $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; }); @@ -985,3 +972,17 @@ }; }); }()); + +angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("bootstrap/choices.tpl.html","
      0\">
    • 0\">
      {{$group.name}}
    "); +$templateCache.put("bootstrap/match-multiple.tpl.html"," × "); +$templateCache.put("bootstrap/match.tpl.html",""); +$templateCache.put("bootstrap/select-multiple.tpl.html","
    "); +$templateCache.put("bootstrap/select.tpl.html","
    "); +$templateCache.put("select2/choices.tpl.html","
    • {{$group.name}}
    "); +$templateCache.put("select2/match-multiple.tpl.html","
  • "); +$templateCache.put("select2/match.tpl.html","{{$select.placeholder}} "); +$templateCache.put("select2/select-multiple.tpl.html","
    "); +$templateCache.put("select2/select.tpl.html","
    "); +$templateCache.put("selectize/choices.tpl.html","
    {{$group.name}}
    "); +$templateCache.put("selectize/match.tpl.html","
    "); +$templateCache.put("selectize/select.tpl.html","
    ");}]);