Luci/cbi question

Hi,
I'm trying to create a web page for entering sets of FTP information like this:

image

I'm doing this with this lua code:

wm = s:taboption("destination_setting", ListValue, "SelectFTP", translate( "Select FTP" ))
wm:value( "ftp1", "FTP1" )
wm:value( "ftp2", "FTP2" )
wm:value( "ftp3", "FTP3" )
wm.rmempty = false
wm.optional = false

tmp = s:taboption("destination_setting", Value, "FTPIPAddress1", translate( "IP Address" ),
                translate("Enter FTP server IP address"))
tmp.datatype = "string"
tmp.rmempty = true
tmp:depends( "SelectFTP", "ftp1" )

tmp = s:taboption("destination_setting", Value, "FTPUsername1", translate( "Username" ),
                translate("Enter FTP server username"))
tmp.datatype = "string"
tmp.rmempty = true
tmp:depends( "SelectFTP", "ftp1" )
...
tmp = s:taboption("destination_setting", Value, "FTPIPAddress2", translate( "IP Address" ),
                translate("Enter FTP server IP address"))
tmp.datatype = "string"
tmp.rmempty = true
tmp:depends( "SelectFTP", "ftp2" )

tmp = s:taboption("destination_setting", Value, "FTPUsername2", translate( "Username" ),
                translate("Enter FTP server username"))
tmp.datatype = "string"
tmp.rmempty = true
tmp:depends( "SelectFTP", "ftp2" )
...

When I go to save, it only writes the FTP information for the displayed FTP settings, ie. the set of settings with the valid "depends" dependency. Is there a way to make it write all settings, in this case, the settings for all FTP entries, not just the single set that are visible?

Will.

While not a direct answer to your question, you may want to consider using TypedSection (with or without cbi/tblsection template )and show the FTP picker drop-down above that.

Maybe @jow or @hnyman can answer that better.

Hi,
Do you mean put the FTP details in their own section? I have tried that, and "depends" only works with settings from the same section.

I ended up resolving this by saving settings at parse time, and writing back non-visible settings manually, like this:


local FTPIPAddress = {}
local FTPUsername = {}
local FTPPassword = {}
local FTPDirectory = {}

local FTPOptions = 10

function m.on_after_save(map)
        local SelectFTP = uci:get("syncit_dest", "main", "SelectFTP")
        local index = 1

        for i=1, FTPOptions do
                if SelectFTP == "ftp" .. i then
                        index = i
                end
        end
        for i=1, FTPOptions do
                if i ~= index then
                        uci:set("syncit_dest", "main", "FTPIPAddress" .. i, FTPIPAddress[i] )
                        uci:set("syncit_dest", "main", "FTPUsername" .. i, FTPUsername[i] )
                        uci:set("syncit_dest", "main", "FTPPassword" .. i, FTPPassword[i] )
                        uci:set("syncit_dest", "main", "FTPDirectory" .. i, FTPDirectory[i] )
                end
        end

        exec("uci commit")
end

function m.on_parse(map)
        for i=1, FTPOptions do
                FTPIPAddress[i] = uci:get("syncit_dest", "main", "FTPIPAddress" .. i)
                FTPUsername[i] = uci:get("syncit_dest", "main", "FTPUsername" .. i)
                FTPPassword[i]= uci:get("syncit_dest", "main", "FTPPassword" .. i)
                FTPDirectory[i]= uci:get("syncit_dest", "main", "FTPDirectory" .. i)
        end
end
1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.