Only update uci config file when the fields validation has passed

I need to Only ever update uci config file if the field has passed validation on Edit .
suppose current config file -

config redirect
          option a 123
          option b 456


m = Map("abc",translate("SETTINGS"),translate(""))
s = m:section(NamedSection, section, "redirect", "")

o = s:option(Value, "a", translate("a name"),translate(""))

o = s:option(Value, "b", translate("b name"),translate(""))

--validation for do not accept balnk "a" if "b" is specified.
function o.validate(self, value, section)
	local a =, "a")
	if value and a == nil then
		return nil, translate("a field value is missing")		
	return value

So on Edit scenario when there is an error blank value for "a" is getting saved in config file.
I don't want to update config value if there is an error occurred.
So how can i prevent to update fields ?

Any suggestions would be appreciated.

You’re validating the values already in the config (…)). You need to verify the values submitted instead which are about to be saved. Use the formvalue() function to retrieve them.

I need to prevent to save config file when there is an error encountered.
It is saving all values other than this validated field.

how to prevent to save config file if luci encountered an error.

It should not do that. If at least one validatior fails, the entire form save should be aborted

1 Like