From 494810393aa062b430f44756e93d9cb00d749732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 15 Jul 2015 17:21:54 +0200 Subject: [PATCH] feat(templating): new template variable selection dropdown now supports accepting custom values that are not an actual selectable value, Fixes #2344 --- public/app/directives/valueSelectDropdown.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/public/app/directives/valueSelectDropdown.js b/public/app/directives/valueSelectDropdown.js index 65b45135fd5..4c0a25ad693 100644 --- a/public/app/directives/valueSelectDropdown.js +++ b/public/app/directives/valueSelectDropdown.js @@ -107,10 +107,14 @@ function (angular, app, _) { vm.moveHighlight(-1); } if (evt.keyCode === 13) { - vm.optionSelected(vm.search.options[vm.highlightIndex], {}, true, false); + if (vm.search.options.length === 0) { + vm.commitChanges(); + } else { + vm.selectValue(vm.search.options[vm.highlightIndex], {}, true, false); + } } if (evt.keyCode === 32) { - vm.optionSelected(vm.search.options[vm.highlightIndex], {}, false, false); + vm.selectValue(vm.search.options[vm.highlightIndex], {}, false, false); } }; @@ -189,8 +193,12 @@ function (angular, app, _) { }; vm.commitChanges = function() { - // make sure one option is selected - if (vm.selectedValues.length === 0) { + // if we have a search query and no options use that + if (vm.search.options.length === 0 && vm.search.query.length > 0) { + vm.variable.current = {text: vm.search.query, value: vm.search.query}; + } + else if (vm.selectedValues.length === 0) { + // make sure one option is selected vm.options[0].selected = true; vm.selectionsChanged(false); }