3.4 Bag Validator
The basic ideas of Bag validator is to make a control of the data which can be inserted as value of a node. This mean that you can set a function of validation for a Bag node with two different sintaxes: as attributes or with the use of the Bag method addValidator().
3.4.1 - Examples
Setting with a node attribute:
# using the prefix validate_ followed by the type of validation.
myform.setItem('list.user.name','',validate_case='capitalize')
# now when you overwrite the value at the path 'list.user.name' the Bag does the control
myform['list.user.name'] = 'John Smith'
Setting using the setValidator method:
# using the prefix validate_ followed by the type of validation. The value of the attribute is the parameter of that validtation
myform.setItem('list.user.name',None,validate_case='capitalize')
# now set the validator with the Bag method addValidator(self, path, validator, parameterString))
myform = Bag()
myform.addValidator('list.user.name','case','capitalize' )
# now when you overwrite the value at the path 'list.user.name' the Bag does the control
myform['list.user.name'] = 'John Smith'
There is also the method removeValidator(self, path, validator) that remove the validator set into the path
3.4.2 - validator function
Actually you can set this validation:
- validate_case: the parameter string can be 'upper', 'lower', 'capitalize'
- validate_inList: the parameter string is a list of the values accepted eg: 'value1,value2,value3'
- validate_length: the parameter string is the min and the max number of char accepted for the value: eg '2,4'
- validate_hostaddr: no parameters
