From bd89d801ba1e0edc816e3ea94b8d8d8335b921f9 Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Thu, 31 Oct 2013 19:10:30 +0100 Subject: Focus input on label click in fluid layout https://fedorahosted.org/freeipa/ticket/3904 --- install/ui/src/freeipa/widget.js | 90 ++++++++++++++++++++++++++++++++++------ 1 file changed, 78 insertions(+), 12 deletions(-) (limited to 'install/ui') diff --git a/install/ui/src/freeipa/widget.js b/install/ui/src/freeipa/widget.js index b6cfdd6d4..63e7a4197 100644 --- a/install/ui/src/freeipa/widget.js +++ b/install/ui/src/freeipa/widget.js @@ -450,7 +450,32 @@ IPA.input_widget = function(spec) { * Focus input element * @abstract */ - that.focus_input = function() {}; + that.focus_input = function() { + + var input = that.get_input(); + + if (!input) { + return; + } else if (input.jquery || input.length === undefined) { + input.focus(); + } else if (input.length) { + input[0].focus(); + } + }; + + /** + * Get input element or array of input elements in case of multivalued + * widgets. + * + * - useful for label.for + * + * @return {null|HTMLElement[]} + */ + that.get_input = function() { + + if (that.input) return that.input; + return null; + }; /** * Mark element as deleted. @@ -533,9 +558,12 @@ IPA.text_widget = function(spec) { style: 'display: none;' }).appendTo(container); + var id = IPA.html_util.get_next_id(that.name); + that.input = $('', { type: that.input_type, name: that.name, + id: id, size: that.size, title: that.tooltip, keyup: function() { @@ -595,13 +623,6 @@ IPA.text_widget = function(spec) { that.display_control.text(''); }; - /** - * @inheritDoc - */ - that.focus_input = function() { - that.input.focus(); - }; - /** * @inheritDoc */ @@ -758,10 +779,20 @@ IPA.multivalued_widget = function(spec) { }; that.focus_last = function() { + if (!that.rows.length) return; var last_row = that.rows[that.rows.length-1]; last_row.widget.focus_input(); }; + that.focus_input = function() { + + if (that.rows.length) { + that.focus_last(); + } else { + that.add_link.focus(); + } + }; + that.add_row = function(values) { var row = {}; that.rows.push(row); @@ -1125,7 +1156,7 @@ IPA.option_widget_base = function(spec, that) { var id = that._option_next_id + input_name; var enabled = that.enabled && option.enabled; - $('', { + option.input_node = $('', { id: id, type: that.input_type, name: input_name, @@ -1135,7 +1166,7 @@ IPA.option_widget_base = function(spec, that) { change: that.on_input_change }).appendTo(container); - $('