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>
Tue, 24 Mar 2020 21:14:18 +0000 (22:14 +0100)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit 22ba6fc40933bee02c3ea93bbda952bb44bf3af1)

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

index b3133a8d317e91e969fd43f8253c81e31f64dd66..917584bb8231889a0e10a1a90c1db14706528e2f 100644 (file)
@@ -1644,7 +1644,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 b78a109bf93a43a0647f63d19facafde16b00f83..0e196df4b018648023af21c3dbe82d97a10f21a0 100644 (file)
@@ -236,7 +236,8 @@ var UICheckbox = UIElement.extend({
                        '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 }));