Good tip Wikus..
you can also do the something similar with SQLFORM.factory and not
define in the model (that way no DB table is created)
in controller
--------------------------------
MY_OPTIONS = ["a","b","c"]
form = SQLFORM.factory(
Field("my_options", "list:string",
default=MY_OPTIONS,widget=SQLFORM.widgets.checkboxes.widget,
requires=[IS_IN_SET(MY_OPTIONS,
multiple=True),IS_NOT_EMPTY()]))
if form.accepts(request.vars):
#code to process form
return dict(form=form)
On Feb 21, 4:03 pm, Wikus van de Merwe <[email protected]>
wrote:
> The easiest way to do that is rely on web2py model -> form transformation
> and use a validator (instead of the custom form).
>
> model
> ------------------------------------------
> MY_OPTIONS = ["a","b","c"]
> db.define_table("my_table",
> db.Field("my_options", "list:string", default=MY_OPTIONS))
>
> db.my_table.my_options.widget = SQLFORM.widgets.checkboxes.widget
> db.my_table.my_options.requires = [IS_IN_SET(MY_OPTIONS, multiple=True),
> IS_NOT_EMPTY()]
>
> controller
> ------------------------------------------
> def my_function():
> if len(request.args):
> form=SQLFORM(db.my_table, request.args[0])
> else:
> form=SQLFORM(db.my_table)
>
> if form.accepts(request.vars):
> redirect(URL(r=request, f='my_next_function', args=[form.vars.id]))
>
> return {"form":form}