[luci] How to perform data integrity checking?

Andrew Grove grove_andrew at hotmail.com
Mon Nov 16 21:24:59 CET 2009


Thanks for the info.  I have a couple more questions below.

>> This is the kind of thing I want but it's not clear how this checking
>>  is done.  I'm using version luci-0.8.7, any insight would be 
>> appreciated.
>
>The mechanism responsible for this is called "uvl" - UCI Validation
>Layer. It is a library which takes uci schema descriptions from
>/lib/uci/schema/default/<configname> and applies them against the
>configuration provided by the user. You need to provide such a
>definition for your configuration in order to enable the checking.
>
>Take a look at the other schema files to see what's the correct syntax
>etc. If something is not clear, ask here - there is no written
>documentation about it yet.

I have reviewed the uvl schema files in /lib/uci/schema/default/ and I was 
wondering if you could describe what a package is or means.  Is the package name
the same as the config file?  

Also there seems to be a lot of the same information, like text labels, in the uvl file
and the config file file.  Is this necessary and which file takes priority if they differ?

>Another approach is to define a .validate function for each field:
>
>  port = s:option(Value, "port", "Port")
>  function port.validate(self, value)
>    if not value or value:match("%D") then
>      return false
>    else
>      return true
>    end
>  end

I tried adding a validate function as suggested above but when I clicked Save I only saw a 
white screen.  This happened whether the value was valid or not.

>> For the listboxes that depended on the enable, they show whatever the
>> first item in there list is, but for my value box it's just empty
>> which is not what I want.  Any idea what would cause this behavior?
>
>Yes, unfortunately the form mapper in LuCI 0.8.7 contained some bugs in
>the processing of the .default property, it is not applied in all fields
>leading to empty values as you have noticed. There is a workaround for
>this, you can override the .cfgvalue function of the affected options to
>inject a default value as needed, example:
>
>  field = s:option(Value, "blah", "blah")
>  function field.cfgvalue(...)
>    return Value.cfgvalue(...) or "my_default_value"
>  end
>

I added the cfgvalue function and was able to be the default setting behavior I
wanted, however, I noticed that if the user does not change a setting with a cfgvalue
function attached to it, then that value is not written to the config file.  If this 
expected behavior?

>
>HTH,
>JoW
 		 	   		  
_________________________________________________________________
Hotmail: Free, trusted and rich email service.
http://clk.atdmt.com/GBL/go/171222984/direct/01/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.subsignal.org/pipermail/luci/attachments/20091116/fa6c1d76/attachment.htm 


More information about the luci mailing list