luci-base: cbi: refactor event handling js
[project/luci.git] / modules / luci-base / luasrc / view / cbi / value.htm
1 <%+cbi/valueheader%>
2         <input data-update="change"<%=
3                 attr("id", cbid) ..
4                 attr("name", cbid) ..
5                 attr("type", self.password and "password" or "text") ..
6                 attr("class", self.password and "cbi-input-password" or "cbi-input-text") ..
7                 attr("value", self:cfgvalue(section) or self.default) ..
8                 ifattr(self.size, "size") ..
9                 ifattr(self.placeholder, "placeholder") ..
10                 ifattr(self.readonly, "readonly") ..
11                 ifattr(self.maxlength, "maxlength")
12         %> />
13         <% if self.password then %><img src="<%=resource%>/cbi/reload.gif" style="vertical-align:middle" title="<%:Reveal/hide password%>" onclick="var e = document.getElementById('<%=cbid%>'); e.type = (e.type=='password') ? 'text' : 'password';" /><% end %>
14         <% if #self.keylist > 0 or self.datatype then -%>
15         <script type="text/javascript">//<![CDATA[
16                 <% if #self.keylist > 0 then -%>
17                 cbi_combobox_init('<%=cbid%>', {
18                 <%-
19                         for i, k in ipairs(self.keylist) do
20                 -%>
21                         <%-=string.format("%q", k) .. ":" .. string.format("%q", self.vallist[i])-%>
22                         <%-if i<#self.keylist then-%>,<%-end-%>
23                 <%-
24                         end
25                 -%>
26                 }, '<%- if not self.rmempty and not self.optional then -%>
27                         <%-: -- Please choose -- -%>
28                         <%- elseif self.placeholder then -%>
29                         <%-= pcdata(self.placeholder) -%>
30                 <%- end -%>', '
31                 <%- if self.combobox_manual then -%>
32                         <%-=self.combobox_manual-%>
33                 <%- else -%>
34                         <%-: -- custom -- -%>
35                 <%- end -%>');
36                 <%- end %>
37                 <% if self.datatype then -%>
38                 cbi_validate_field('<%=cbid%>', <%=tostring((self.optional or self.rmempty) == true)%>, '<%=self.datatype:gsub("\\", "\\\\"):gsub("'", "\\'")%>');
39                 <%- end %>
40         //]]></script>
41         <% end -%>
42 <%+cbi/valuefooter%>