From f2965b759ad26c5f11b1cea43c5e4e6c5ac3b3b8 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 3 Aug 2020 15:17:40 +0200 Subject: [PATCH] luci-base: ui.js: implement AbstractElement.setPlaceholder() Signed-off-by: Jo-Philipp Wich --- .../htdocs/luci-static/resources/ui.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/modules/luci-base/htdocs/luci-static/resources/ui.js b/modules/luci-base/htdocs/luci-static/resources/ui.js index 91a93b9e90..7823182f04 100644 --- a/modules/luci-base/htdocs/luci-static/resources/ui.js +++ b/modules/luci-base/htdocs/luci-static/resources/ui.js @@ -101,6 +101,32 @@ var UIElement = baseclass.extend(/** @lends LuCI.ui.AbstractElement.prototype */ this.node.value = value; }, + /** + * Set the current placeholder value of the input widget. + * + * @instance + * @memberof LuCI.ui.AbstractElement + * @param {string|string[]|null} value + * The placeholder to set for the input element. Only applicable to text + * inputs, not to radio buttons, selects or similar. + */ + setPlaceholder: function(value) { + var node = this.node ? this.node.querySelector('input,textarea') : null; + if (node) { + switch (node.getAttribute('type') || 'text') { + case 'password': + case 'search': + case 'tel': + case 'text': + case 'url': + if (value != null && value != '') + node.setAttribute('placeholder', value); + else + node.removeAttribute('placeholder'); + } + } + }, + /** * Check whether the current input value is valid. * -- 2.30.2