luci-base: form.js: fix rendering of button widgets
authorJo-Philipp Wich <jo@mein.io>
Thu, 8 Aug 2019 06:34:27 +0000 (08:34 +0200)
committerJo-Philipp Wich <jo@mein.io>
Wed, 14 Aug 2019 20:58:15 +0000 (22:58 +0200)
Also introduce an `onclick` property to allow registering custom button
action handler.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/form.js

index 1c1c9c8c918c17156fc1e2fa6253a8ad8a9455eb..a417616d2fd012dd055fb63fd75fe3fe2a707c6b 100644 (file)
@@ -1585,28 +1585,29 @@ var CBIButtonValue = CBIValue.extend({
        __name__: 'CBI.ButtonValue',
 
        renderWidget: function(section_id, option_index, cfgvalue) {
-               var value = (cfgvalue != null) ? cfgvalue : this.default;
+               var value = (cfgvalue != null) ? cfgvalue : this.default,
+                   hiddenEl = new ui.Hiddenfield(value, { id: this.cbid(section_id) }),
+                   outputEl = E('div');
 
                if (value !== false)
-                       return E([
-                               E('input', {
-                                       'type': 'hidden',
-                                       'id': this.cbid(section_id)
-                               }),
+                       L.dom.content(outputEl, [
                                E('input', {
                                        'class': 'cbi-button cbi-button-%s'.format(this.inputstyle || 'button'),
-                                       'type': 'submit',
-                                       //'id': this.cbid(section_id),
-                                       //'name': this.cbid(section_id),
+                                       'type': 'button',
                                        'value': this.inputtitle || this.title,
-                                       'click': L.bind(function(ev) {
+                                       'click': L.bind(this.onclick || function(ev) {
                                                ev.target.previousElementSibling.value = ev.target.value;
                                                this.map.save();
                                        }, this)
                                })
                        ]);
                else
-                       return document.createTextNode(' - ');
+                       L.dom.content(outputEl, ' - ');
+
+               return E([
+                       outputEl,
+                       hiddenEl.render()
+               ]);
        }
 });