Thank Richard.

I use: query = (db.tablegroup.parent==None),
In this case: parent = 0 --> not work and I want update: parent = None. 
You have any idea?

On Sunday, March 6, 2011 11:11:40 PM UTC+7, Richard wrote:
>
> What is this for :
>
> form[0][0][1] = TD(my_select) 
>
>
my_select = SELECT(*table_options('tablegroup'), _name=field, 
_id='table_'+reference, _class='reference')

def table_option(table, id=None, order=None, space=''):
    rows = db(db[table].parent==id).select(orderby=order)
    option = []
    if (space =='') & (id !=None):
        row = db(db[table].id==id).select().first()
        option = [OPTION(row.name,_value=row.id)]
        if len(request.args) == 2:
            field = table if request.args(0)<>table else 'parent'
            if db[request.args(0)](request.args(1))[field]==row.id: 
                option = 
[OPTION(row.name,_value=row.id,_selected='selected')]
        space = '---'
    for row in rows:
        op = [OPTION(space+row.name,_value=row.id)]
        if len(request.args) == 2:
            field = table if request.args(0)<>table else 'parent'
            if db[request.args(0)](request.args(1))[field]==row.id: 
                op = 
[OPTION(space+row.name,_value=row.id,_selected='selected')]
        option += op + table_option(table, row.id, order, space+'---')     
    return option        







 

> ???
>
> 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