custom validator for multis

This commit is contained in:
gwen 2012-11-22 11:53:51 +01:00
parent 426e64ca39
commit bf112bc756
1 changed files with 9 additions and 5 deletions

View File

@ -165,14 +165,14 @@ class Option(HiddenBaseType, DisabledBaseType):
:param value: the option's value :param value: the option's value
:param validate: if true enables ``self._validator`` validation :param validate: if true enables ``self._validator`` validation
""" """
# customizing the validator
if validate and value is not None and self._validator is not None:
if not self._validator(value, **self._validator_args):
return False
# generic calculation # generic calculation
if self.multi == False: if self.multi == False:
# None allows the reset of the value # None allows the reset of the value
if value != None: if value != None:
# customizing the validator
if validate and self._validator is not None and \
not self._validator(value, **self._validator_args):
return False
return self._validate(value) return self._validate(value)
else: else:
if not isinstance(value, list): if not isinstance(value, list):
@ -180,8 +180,12 @@ class Option(HiddenBaseType, DisabledBaseType):
"for option {1} which must be a list".format(value, "for option {1} which must be a list".format(value,
self._name)) self._name))
for val in value: for val in value:
# None allows the reset of the value
if val != None: if val != None:
# None allows the reset of the value # customizing the validator
if validate and self._validator is not None and \
not self._validator(val, **self._validator_args):
return False
if not self._validate(val): if not self._validate(val):
return False return False
return True return True