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
This commit is contained in:
Petr Voborník
2012-02-23 16:16:23 +01:00
committed by Petr Vobornik
parent 87c2b00bf8
commit 34f742bec2

View File

@@ -2144,14 +2144,7 @@ IPA.combobox_widget = function(spec) {
name: 'list', name: 'list',
size: that.size, size: that.size,
style: 'width: 100%', style: 'width: 100%',
change: function() { change: that.select_on_change
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);
}
}).appendTo(div); }).appendTo(div);
if (that.undo) { if (that.undo) {
@@ -2161,6 +2154,18 @@ IPA.combobox_widget = function(spec) {
that.create_error_link(container); 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() { that.open = function() {
if (!that.read_only) if (!that.read_only)
that.list_container.css('visibility', 'visible'); that.list_container.css('visibility', 'visible');
@@ -2281,7 +2286,8 @@ IPA.combobox_widget = function(spec) {
that.create_option = function(label, value) { that.create_option = function(label, value) {
return $('<option/>', { return $('<option/>', {
text: label, text: label,
value: value value: value,
click:that.select_on_change
}).appendTo(that.list); }).appendTo(that.list);
}; };