From 1f451d4021ca2aba8a9d82cb2feb1e450764c0c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kr=C3=BCger?= Date: Sat, 28 Jan 2023 20:34:52 +0100 Subject: [PATCH 1/2] gluon-web-model: fix issue with warning blocking save on private-wifi The other bugfix which made this element inherit from AbstractValue caused AbstractValue:validate() to be inherited aswell Now added an if so validate only runs if a datatype is set (since Element is meant as a generic way to extend web-model without modifying web-model - also to add custom inputs - just hiding it behind an if sounds like a sane solution) --- .../usr/lib/lua/gluon/web/model/classes.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/package/gluon-web-model/luasrc/usr/lib/lua/gluon/web/model/classes.lua b/package/gluon-web-model/luasrc/usr/lib/lua/gluon/web/model/classes.lua index 93279c3b..d09b9bb8 100644 --- a/package/gluon-web-model/luasrc/usr/lib/lua/gluon/web/model/classes.lua +++ b/package/gluon-web-model/luasrc/usr/lib/lua/gluon/web/model/classes.lua @@ -429,6 +429,23 @@ function Element:__init__(template, kv, ...) self.error = false end +function Element:parse(http) + if not self.datatype then + self.state = M.FORM_VALID + return + end + + return AbstractValue:parse(http) +end + +function Element:validate() + if not self.datatype then + return true + end + + AbstractValue:validate() +end + local Section = class(Node) M.Section = Section From ad8cfe02c2cf62567e3fd474ecbb7bcc258e7e30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kr=C3=BCger?= Date: Sat, 28 Jan 2023 20:46:41 +0100 Subject: [PATCH 2/2] gluon-web-model: fix Warning field not being hidden "not self.title" doesn't work because of "self.title = title or """ --- .../files/lib/gluon/web/view/model/warning.html | 8 ++++---- .../lib/gluon/config-mode/model/admin/privatewifi.lua | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/package/gluon-web-model/files/lib/gluon/web/view/model/warning.html b/package/gluon-web-model/files/lib/gluon/web/view/model/warning.html index af063ec5..8394bb13 100644 --- a/package/gluon-web-model/files/lib/gluon/web/view/model/warning.html +++ b/package/gluon-web-model/files/lib/gluon/web/view/model/warning.html @@ -1,14 +1,14 @@ -<%- if self.title or self.content then -%> +<%- if not self.hide then -%>
> <%- if self.content then -%> - <%=self.content%> + <%= self.content %> <%- else -%> - <%=self.title%>
- <%=self.description%> + <%= self.title %>
+ <%= self.description %> <%- end -%>
<%- end -%> diff --git a/package/gluon-web-private-wifi/luasrc/lib/gluon/config-mode/model/admin/privatewifi.lua b/package/gluon-web-private-wifi/luasrc/lib/gluon/config-mode/model/admin/privatewifi.lua index 9d29b2b6..c69d22c3 100644 --- a/package/gluon-web-private-wifi/luasrc/lib/gluon/config-mode/model/admin/privatewifi.lua +++ b/package/gluon-web-private-wifi/luasrc/lib/gluon/config-mode/model/admin/privatewifi.lua @@ -27,10 +27,11 @@ local enabled = s:option(Flag, "enabled", translate("Enabled")) enabled.default = uci:get('wireless', primary_iface) and not uci:get_bool('wireless', primary_iface, "disabled") local warning = s:element('model/warning', { - content = mesh_on_wan and translate( + content = translate( 'Meshing on WAN interface is enabled. ' .. 'This can lead to problems.' - ) or nil, + ), + hide = not mesh_on_wan, }, 'warning') warning:depends(enabled, true)