custom validator for multis
authorgwen <gremond@cadoles.com>
Thu, 22 Nov 2012 10:53:51 +0000 (11:53 +0100)
committergwen <gremond@cadoles.com>
Thu, 22 Nov 2012 10:53:51 +0000 (11:53 +0100)
tiramisu/option.py

index a0ec783..642dc7e 100644 (file)
@@ -165,14 +165,14 @@ class Option(HiddenBaseType, DisabledBaseType):
         :param value: the option's value
         :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
         if self.multi == False:
             # None allows the reset of the value
             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)
         else:
             if not isinstance(value, list):
@@ -180,8 +180,12 @@ class Option(HiddenBaseType, DisabledBaseType):
                         "for option {1} which must be a list".format(value,
                         self._name))
             for val in value:
+                # None allows the reset of the value
                 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):
                         return False
         return True