From 46861a527e0ba67a99b21eb8af4e5790922f5da1 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Thu, 8 Aug 2019 08:34:27 +0200 Subject: [PATCH] luci-base: form.js: fix rendering of button widgets Also introduce an `onclick` property to allow registering custom button action handler. Signed-off-by: Jo-Philipp Wich --- .../htdocs/luci-static/resources/form.js | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/modules/luci-base/htdocs/luci-static/resources/form.js b/modules/luci-base/htdocs/luci-static/resources/form.js index 1c1c9c8c9..a417616d2 100644 --- a/modules/luci-base/htdocs/luci-static/resources/form.js +++ b/modules/luci-base/htdocs/luci-static/resources/form.js @@ -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() + ]); } }); -- 2.25.1