0

I want to make visible or hidden a textbox based on radio option selected in openWRT Luci.

Is there any way to avoid JavaScript?

Thanks in advance

Raihanhbh
  • 77
  • 1
  • 10

1 Answers1

0

yah Raihanhbh it's available in openwrt luci, you need to use dependent. base on luci documentation let describe how depends work.

CBI provides the :depends() method on option objects that allow to dynamically show or hide the object field depending on the value in some other field.

the method is called as obj:depends( some_other_option, value ). "depends" parameter is linked with "OR"

--Now let an example

local t=require"luci.model.network".init()
local e=require"luci.model.firewall".init()
local i=require"luci.util"
local e=require"luci.model.uci".cursor()
local u=require"luci.sys".net

--Create model

m = Map("firewall1", translate("firewall"))
s = m:section(NamedSection, "dmz", "")

--create radio button

f1 = s:option(ListValue, "dmz", "Current DMZ Status:") -- Creates an element list (select box)
f1.widget="radio"
f1:value("disable", "Disable") -- Key and value pairs
f1:value("enable", "Enable")
f1.default = "disable"
function f1.write(self, section, value)
    return Flag.write(self, section, value)
end

--TextBox

f2=s:option(Value,"netmask1")
f2:depends("dmz","disable")
function f2.cfgvalue(self,section)
    local val = self.map:get(section, "netmask")--Value.cfgvalue(self, section)
    return val
end

--Return model

return m;

above textbox netmask1 dependent on radio button dmz

shamim
  • 6,640
  • 20
  • 85
  • 151