What is this for :

form[0][0][1] = TD(my_select)

???

Default choice to be charged into the dropdown field??

There is a option for default choice...

And there is a syntax to be used into controller to set default value when
needed if it is not to be set everywhere the model is used.

db.tablegroup.parent.requires = IS_NULL_OR(IS_IN_DB(db, 'tablegroup.id',
'%(name)s', zero=None)) # in your controller before call crud.create for
example

For default choice see this section in the book :

http://web2py.com/book/default/chapter/06?search=default#Record-Representation

Beside field constructor tag

There is also keepvalue that alow you to prepopulate form with value of your
choice.

Hope it help.

Richard

On Sun, Mar 6, 2011 at 4:59 AM, toan75 <toa...@gmail.com> wrote:

> Hi all,
>
> Please  help me with the problem of dropdown selection.
> It work fin by default:  select blank option in the drop down, it update
> value of field reference = None
> But i need change drop down list: form[0][0][1] = TD(my_select)
> Now, it update value = 0 (not None) and I can't update: db(
> db.tablegroup.id==form.vars.id).update(field=None)
> How i use None instead 0 ?
>
> MODEL:
>
> db.define_table('tablegroup',
>     Field('parent', 'reference tablegroup', requires =
> IS_NULL_OR(IS_IN_DB(db, 'tablegroup.id', '%(name)s', zero=None))),
>     Field('name', unique=True),
>     migrate=True)
>
> CONTROL:
>
> def create():
>     form=crud.create(db.tablegroup)
>     form[0][0][1] = TD(my_select)
>     if form.accepts(request.vars, session): pass
>     return dict(form=form)
>
>

Reply via email to