From: Jo-Philipp Wich Date: Thu, 8 Aug 2019 06:34:27 +0000 (+0200) Subject: luci-base: form.js: fix rendering of button widgets X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=46861a527e0ba67a99b21eb8af4e5790922f5da1;p=project%2Fluci.git 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 --- diff --git a/modules/luci-base/htdocs/luci-static/resources/form.js b/modules/luci-base/htdocs/luci-static/resources/form.js index 1c1c9c8c91..a417616d2f 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() + ]); } });