From 34f742bec2dec8fd4ade51946cd38b9dea123295 Mon Sep 17 00:00:00 2001 From: Petr Voborník Date: Thu, 23 Feb 2012 16:16:23 +0100 Subject: Fixed selection of single value in combobox When editable combobox had only one option and input field was cleared, the option couldn't be selected if it was selected before. This patch adds click handler to option elements. The handler calls select_on_change. When different option is selected select_on_change is executed twice. To avoid duplicate call of value_changed an open state of option area is checked. In first pass the area will be closed so it won't be executed in second. When selected option is clicked, only onclick handler is processed. This patch assumes that select event will be processed before click event. https://fedorahosted.org/freeipa/ticket/2070 --- install/ui/widget.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'install/ui/widget.js') diff --git a/install/ui/widget.js b/install/ui/widget.js index 5ce7261e..a54c9b82 100644 --- a/install/ui/widget.js +++ b/install/ui/widget.js @@ -2144,14 +2144,7 @@ IPA.combobox_widget = function(spec) { name: 'list', size: that.size, style: 'width: 100%', - change: function() { - var value = $('option:selected', that.list).val(); - that.input.val(value); - IPA.select_range(that.input, 0, 0); - - that.close(); - that.value_changed.notify([[value]], that); - } + change: that.select_on_change }).appendTo(div); if (that.undo) { @@ -2161,6 +2154,18 @@ IPA.combobox_widget = function(spec) { that.create_error_link(container); }; + that.select_on_change = function() { + + if (!that.is_open()) return; + + var value = $('option:selected', that.list).val(); + that.input.val(value); + IPA.select_range(that.input, 0, 0); + + that.close(); + that.value_changed.notify([[value]], that); + }; + that.open = function() { if (!that.read_only) that.list_container.css('visibility', 'visible'); @@ -2281,7 +2286,8 @@ IPA.combobox_widget = function(spec) { that.create_option = function(label, value) { return $('