From: Jo-Philipp Wich Date: Wed, 18 Jul 2018 09:23:50 +0000 (+0200) Subject: luci-base: cbi.js: add cbi_submit() helper X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=392fd02383faeeae0c1cb9c40717c9a34ca4db6c;p=oweals%2Fluci.git luci-base: cbi.js: add cbi_submit() helper Signed-off-by: Jo-Philipp Wich (cherry picked from commit 7b43e81c9b88df9623cfa22a79627558787378ea) --- diff --git a/modules/luci-base/htdocs/luci-static/resources/cbi.js b/modules/luci-base/htdocs/luci-static/resources/cbi.js index ddbff8341..89dfac9e4 100644 --- a/modules/luci-base/htdocs/luci-static/resources/cbi.js +++ b/modules/luci-base/htdocs/luci-static/resources/cbi.js @@ -1306,6 +1306,28 @@ function cbi_tag_last(container) } } +function cbi_submit(elem, name, value, action) +{ + var form = elem.form || findParent(elem, 'form'); + + if (!form) + return false; + + if (action) + form.action = action; + + if (name) { + var hidden = form.querySelector('input[type="hidden"][name="%s"]'.format(name)) || + E('input', { type: 'hidden', name: name }); + + hidden.value = value || '1'; + form.appendChild(hidden); + } + + form.submit(); + return true; +} + String.prototype.format = function() { if (!RegExp)