You need to 1) extend Validator and 2) provide an options method. This
should do:
from pydal.validators import Validator
class IS_IN_SET_CONDITIONAL(Validator):
def __init__(self, liste, expression, error_message="Value not allowed"
):
self.expression = expression
self.error_message = error_message
self.liste = liste
def __call__(self, value):
if self.expression:
if value in self.liste:
return (value,None)
else:
return(value, self.error_message)
else:
return (value, None)
def options(self):
return self.liste
On Sunday, 9 February 2020 21:58:25 UTC-8, Fabian wrote:
>
> Hello Guys,
>
> I made a Validator which should check if the value is in the list, but
> only if an expression is True.
> It works fine BUT it produces no dropdown. Hope you can help me:
>
> Class:
>
> class IS_IN_SET_CONDITIONAL():
> def __init__(self, liste, expression, error_message="Value not
> allowed"):
> self.expression = expression
> self.error_message = error_message
> self.liste = liste
>
> def __call__(self, value):
> if self.expression:
> if value in liste:
> return (value,None)
> else:
> return(value, self.error_message)
>
> else:
> return (value, None)
>
>
> Field:
>
> Field("Letter", label="Letter", requires=IS_IN_SET_CONDITIONAL(['A', 'B',
> 'C'], Expression)),
>
>
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/web2py/d80d11a0-ecf3-44be-9c1d-8405b0029bdf%40googlegroups.com.