You do not sent it in the widget.You have to set the "default" attribute for the field.
On Dec 21, 5:01 am, max <[email protected]> wrote: > Hi, > is it possible to set a default value to a widgets.options.widget? > > model: > db = DAL('sqlite://storage.sqlite') > db.define_table('mytable', > Field('options_1', 'text', widget = > SQLFORM.widgets.options.widget ), > Field('options_2', 'text', widget = > SQLFORM.widgets.options.widget )) > > db.mytable.options_1.requires = [IS_IN_SET(['option_1', 'option_2', > 'option_3', 'option_4', 'unknown'], zero = None)] > db.mytable.options_2.requires = [IS_IN_SET(['option_1', 'option_2', > 'option_3', 'option_4', 'unknown'], zero = None)] > > controller: > from gluon.tools import Crud > > def index(): > crud = Crud(globals(), db) > if request.args(0): > values = db(db.mytable.id == > request.args(0)).select(db.mytable.ALL)[0] > form = crud.update(db.mytable, request.args(0), onvalidation = > validate_values) > ##### > # How to set the default value (<option value="unknown" > selected="selected">unknown</option>) > # mean stuff like > # if values.option_1 == None: > # db.mytable.option_1 = 'unknown' > # or > # > # if values.option_2 == None: > # form.custom.dspval.option_2 = 'unknown' > # > # This does not work properly! Any suggestions? > # Is it posible to create an optionswidget, which must not be > selected and can be empty? > ##### > else: > values = None > form = crud.create(db.mytable) > return dict(form = form, values = values) > > def validate_values(form): > for value in form.vars: > if form.vars[value] == 'unknown': > form.vars[value] = None > > In this special case the user have to select 'unknown' if he didn't > know the value during record creation, but later (during update), the > user must not select a value, None values are automatically set to > unknown. > > thanks > max

