On Nov 16, 3:49 pm, Kostas M <[email protected]> wrote:
> I tried this in a controller and worked fine:
>
> def factory():
>     options = ['a','b','c']
>     form = SQLFORM.factory(Field('Optimizers',
> requires=IS_IN_SET(options,multiple='multiple')))
>     if form.accepts(request.vars, session):
>         response.flash = 'form accepted'
>     elif form.errors:
>         response.flash = 'form has errors'
>     return dict(form = form, form_options = form.vars.Optimizers)
>
> Note that according to the web2py book: "The elements of the set must
> always be strings unless this validator is preceded by IS_INT_IN_RANGE
> (which converts the value to int) or IS_FLOAT_IN_RANGE (which converts
> the value to float)"
>
> I have also 2 questions though if somebody can help:
>    1. If nothing is selected why the form is accepted?

Because multiple is not False, but I am not sure about the logic.
No selection should still fail because it is not in the set,
i.e. multiple should mean 1 or more, not zero or more.

>    2. If I try to use multiple validators in requires=[] of the
> SQLFORM.factory, only the last validator of the 'requires' list is
> enforced. Is this a bug? The tried code is:
>
> form=SQLFORM.factory(Field('Optimizers',requires=[IS_IN_SET(options,multiple='multiple'),
> IS_NOT_EMPTY()] ))

This is just a side effect of the above case.
Both validators are being enforced but IS_IN_SET is accepting an empty
input.

Reply via email to