diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/node_config.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/node_config.lua index f2ced5f22..f384eec26 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/node_config.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/node_config.lua @@ -36,6 +36,21 @@ end) for k, v in pairs(groups) do o:value(k) end +o.write = function(self, section, value) + value = api.trim(value) + local lower = value:lower() + + if lower == "" or lower == "default" then + return m:del(section, self.option) + end + + for _, v in ipairs(self.keylist or {}) do + if v:lower() == lower then + return m:set(section, self.option, v) + end + end + m:set(section, self.option, value) +end o = s:option(ListValue, "type", translate("Type")) diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/node_subscribe.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/node_subscribe.lua index 6a6058741..3a4900923 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/node_subscribe.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/node_subscribe.lua @@ -176,7 +176,7 @@ o = s:option(Value, "remark", translate("Remarks")) o.width = "auto" o.rmempty = false o.validate = function(self, value, section) - value = (value or ""):match("^%s*(.-)%s*$") + value = api.trim(value) if value == "" then return nil, translate("Remark cannot be empty.") end @@ -187,7 +187,7 @@ o.validate = function(self, value, section) return false end end) - if duplicate then + if duplicate or value:lower() == "default" then return nil, translate("This remark already exists, please change a new remark.") end return value diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/node_subscribe_config.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/node_subscribe_config.lua index e78e5ff6f..8619ad967 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/node_subscribe_config.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/node_subscribe_config.lua @@ -89,7 +89,7 @@ s.dynamic = false o = s:option(Value, "remark", translate("Subscribe Remark")) o.rmempty = false o.validate = function(self, value, section) - value = (value or ""):match("^%s*(.-)%s*$") + value = api.trim(value) if value == "" then return nil, translate("Remark cannot be empty.") end @@ -100,7 +100,7 @@ o.validate = function(self, value, section) return false end end) - if duplicate then + if duplicate or value:lower() == "default" then return nil, translate("This remark already exists, please change a new remark.") end return value diff --git a/luci-app-passwall/luasrc/view/passwall/node_list/link_add_node.htm b/luci-app-passwall/luasrc/view/passwall/node_list/link_add_node.htm index 19291fcd8..e71efdbf1 100644 --- a/luci-app-passwall/luasrc/view/passwall/node_list/link_add_node.htm +++ b/luci-app-passwall/luasrc/view/passwall/node_list/link_add_node.htm @@ -126,8 +126,16 @@ local api = require "luci.passwall.api" var val = input.value.trim(); if (!val) return; + if (val.toLowerCase() === "default") { + var emptyLi = Array.from(list.querySelectorAll(".dropdown-item")) + .find(function(el){ return !el.dataset.value; }); + if (emptyLi) selectItem(emptyLi); + input.value = ""; + return; + } + var li = Array.from(list.querySelectorAll(".dropdown-item")).find(function(el){ - return el.dataset.value === val; + return el.dataset.value.toLowerCase() === val.toLowerCase(); }); if (!li) { li = document.createElement("li");