diff --git a/acute/acute.select/acute.select.js b/acute/acute.select/acute.select.js index 74225b9..509a512 100644 --- a/acute/acute.select/acute.select.js +++ b/acute/acute.select/acute.select.js @@ -62,12 +62,17 @@ angular.module("acute.select", []) var words = $scope.acOptions.split(' '); var len = words.length; $scope.textField = null; + $scope.valField = null; $scope.dataFunction = null; if (len > 3) { if (len > 4) { var label = words[len - 5]; // E.g. colour.name $scope.textField = label.split(".")[1]; + + var val = words[len - 3].split('.'); + if (val.length > 1) // E.g. colour.val + $scope.valField = val[1]; } var dataName = words[len - 1]; @@ -141,7 +146,11 @@ angular.module("acute.select", []) $scope.setInitialSelection = function() { if ($scope.model) { $scope.initialSelection = angular.copy($scope.model); - $scope.initialItem = $scope.getItemFromDataItem($scope.model, 0); + + if (!isNaN($scope.initialSelection)) + $scope.initialSelection = $scope.initialSelection * 1; + + $scope.initialItem = $scope.getItemFromDataItem($scope.initialSelection, 0); $scope.confirmedItem = $scope.selectedItem = $scope.initialItem; $scope.comboText = $scope.confirmedItem ? $scope.confirmedItem.text : ""; } @@ -164,7 +173,7 @@ angular.module("acute.select", []) // If not currently filtering if (!$scope.searchText) { // Look for a matching item - if (dataItem === selectedDataItem || (key && selectedDataItem && dataItem[key] == selectedDataItem[key])) { + if (dataItem === selectedDataItem || (key && selectedDataItem && dataItem[key] == selectedDataItem[key]) || ( $scope.valField && item.value === selectedDataItem )) { confirmSelection(item); foundSelected = true; } @@ -254,6 +263,9 @@ angular.module("acute.select", []) else if (dataItem[$scope.textField]) { item = { "text": dataItem[$scope.textField], "value": dataItem, "index": itemIndex }; } + else if ($scope.valField){ + item = { "text": "", "value": dataItem, "index": itemIndex}; + } } return item; }; @@ -1032,4 +1044,4 @@ angular.module("acute.select", []) defaultSettings[settingName] = value; } } -}); \ No newline at end of file +});