luci-base: form.js / ui.js: tie form labels to widgets
authorJo-Philipp Wich <jo@mein.io>
Tue, 24 Mar 2020 20:57:21 +0000 (21:57 +0100)
committerJo-Philipp Wich <jo@mein.io>
Thu, 7 May 2020 17:40:49 +0000 (19:40 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit 22ba6fc40933bee02c3ea93bbda952bb44bf3af1)
(cherry picked from commit 82fb5a67d39d965595d2ad833dbf930e559c0202)

modules/luci-base/htdocs/luci-static/resources/form.js
modules/luci-base/htdocs/luci-static/resources/ui.js

index 51893925fe7aade8816155c2ffcdb76e0d0f7872..e547260e4e89579f0f889f1e5d40a6e9a9d674ef 100644 (file)
@@ -1642,7 +1642,16 @@ var CBIValue = CBIAbstractValue.extend({
                        if (typeof(this.title) === 'string' && this.title !== '') {
                                optionEl.appendChild(E('label', {
                                        'class': 'cbi-value-title',
-                                       'for': 'widget.cbid.%s.%s.%s'.format(config_name, section_id, this.option)
+                                       'for': 'widget.cbid.%s.%s.%s'.format(config_name, section_id, this.option),
+                                       'click': function(ev) {
+                                               var node = ev.currentTarget,
+                                                   elem = node.nextElementSibling.querySelector('#' + node.getAttribute('for')) || node.nextElementSibling.querySelector('[data-widget-id="' + node.getAttribute('for') + '"]');
+
+                                               if (elem) {
+                                                       elem.click();
+                                                       elem.focus();
+                                               }
+                                       }
                                },
                                this.titleref ? E('a', {
                                        'class': 'cbi-title-ref',
index 97cdbf391c3762b4f32063a927b7c9c792ec0775..dfc3dbdf02bbed03cdd452d57b1189fbc8598644 100644 (file)
@@ -556,7 +556,8 @@ var UICheckbox = UIElement.extend(/** @lends LuCI.ui.Checkbox.prototype */ {
                        'name': this.options.name,
                        'type': 'checkbox',
                        'value': this.options.value_enabled,
-                       'checked': (this.value == this.options.value_enabled) ? '' : null
+                       'checked': (this.value == this.options.value_enabled) ? '' : null,
+                       'data-widget-id': this.options.id ? 'widget.' + this.options.id : null
                }));
 
                frameEl.appendChild(E('label', { 'for': id }));