summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/luasrc/view/cbi/dropdown.htm
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2018-06-08 07:29:44 +0200
committerJo-Philipp Wich <jo@mein.io>2018-06-08 08:14:36 +0200
commit9d4849072901b2a4bcf3a99492ade1e1cb54930d (patch)
tree1d5c5ab9d692a230989798eb7e9565f982d193d3 /modules/luci-base/luasrc/view/cbi/dropdown.htm
parent4cca96ef091857b6bfe839d7612da00745c530b6 (diff)
luci-base: add markup, JS and CSS for new dropdown
This commit introduces the required code for a new, markup based dropdown widget which can be used as a styleable alternative to select boxes or radio/checkbox button groups. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-base/luasrc/view/cbi/dropdown.htm')
-rw-r--r--modules/luci-base/luasrc/view/cbi/dropdown.htm42
1 files changed, 42 insertions, 0 deletions
diff --git a/modules/luci-base/luasrc/view/cbi/dropdown.htm b/modules/luci-base/luasrc/view/cbi/dropdown.htm
new file mode 100644
index 0000000000..bdf7248375
--- /dev/null
+++ b/modules/luci-base/luasrc/view/cbi/dropdown.htm
@@ -0,0 +1,42 @@
+<%+cbi/valueheader%>
+
+<%-
+ local selected = { }
+
+ if self.multiple then
+ local val
+ for val in luci.util.imatch(self:cfgvalue(section)) do
+ selected[val] = true
+ end
+ else
+ selected[self:cfgvalue(section)] = true
+ end
+
+ if not next(selected) and self.default then
+ selected[self.default] = true
+ end
+-%>
+
+<div class="cbi-dropdown"<%=
+ attr("name", cbid) ..
+ attr("display-items", self.display or self.size or 3) ..
+ attr("dropdown-items", self.dropdown or self.display or self.size or 5) ..
+ attr("placeholder", self.placeholder or translate("-- please select --")) ..
+ ifattr(self.multiple, "multiple", "multiple") ..
+ ifattr(self.optional or self.rmempty, "optional", "optional")
+%>>
+ <ul>
+ <% local i, key; for i, key in pairs(self.keylist) do %>
+ <li<%=
+ attr("data-index", i) ..
+ attr("data-depends", self:deplist2json(section, self.deplist[i])) ..
+ attr("value", key) ..
+ ifattr(selected[key], "selected", "selected")
+ %>>
+ <%=pcdata(self.vallist[i])%>
+ </li>
+ <% end %>
+ </ul>
+</div>
+
+<%+cbi/valuefooter%>