Actually I am not using the SQLFORM. I am using the code for dynamic search 
form from (http://www.web2pyslices.com/slice/show/1403/dynamic-search). I 
want to modify the code such that for the fields with validators, it should 
show the selection menu. So I want to add  a check in the code below to 
detect if a field is having validator set, then use the SELECT command with 
the validator set values as argument. So far, I am not able to achieve it.

Can you please recommend something in context here?

Here is the code from the slice :

def dynamic_search(table):
    tbl = TABLE()
    selected = []
    ops = ['equals','not equal','greater than','less than',
           'starts with','ends with','contains']
    query = table.id > 0    
    for field in table.fields:
        chkval = request.vars.get('chk'+field,None)
        txtval = request.vars.get('txt'+field,None)
        opval = request.vars.get('op'+field,None)
        row = TR(TD(INPUT(_type="checkbox",_name="chk"+field,
                          value=chkval=='on')),
                 TD(field),TD(SELECT(ops,_name="op"+field,
                                     value=opval)),
                 TD(INPUT(_type="text",_name="txt"+field,
                          _value=txtval)))
        tbl.append(row)
        if chkval:
            if txtval:
                query &= build_query(table[field], 
                                opval,txtval)
            selected.append(table[field])           
    form = FORM(tbl,INPUT(_type="submit"))
    results = db(query).select(*selected)
    return form, results

Thanks,
Sarbjit



On Friday, July 26, 2013 1:37:26 PM UTC+5:30, Massimo Di Pierro wrote:
>
> Exactly. Complete code in case you have errors:
>
> #model
> db.define_table('persons',Field('gender'))
> db.persons.gender.requires = IS_IN_SET(['Male', 'Female'])
>
> #controller default.py
> def index():
>     form = SQLFORM(db.persons).process()
>     return locals()
>
> #views default/index.html
> {{extend 'layout.html'}}
> {{=form}}
>
>
> Mind we tend to call table names with singular not plural (person, not 
> persons). This will make your code more readable.
>
> On Friday, 26 July 2013 02:57:21 UTC-5, viniciusban wrote:
>>
>> It's done automaticaly by web2py. 
>>
>> On Fri, Jul 26, 2013 at 2:29 AM, Sarbjit singh <[email protected]> 
>> wrote: 
>> > I have a db where I have set validator IS_IN_SET on a particular field. 
>> I am 
>> > generating table rows (to be used as form), so I need to check if a 
>> > particular field is having IS_IN_SET validator set and I want to 
>> retrieve 
>> > the set values. Reason I want to do this is that I am generating a 
>> dynamic 
>> > form based on the table fields and for the fields having IS_IN_SET 
>> validtor, 
>> > I want to show the "Drop Down" menu rather than Text Field and wants to 
>> > populate it with the Validator values. 
>> > 
>> > db.define_table('persons',Field('gender') 
>> > db.persons.gender.requires = IS_IN_SET(['Male', 'Female']) 
>> > 
>> > -Sarbjit 
>> > 
>> > -- 
>> > 
>> > --- 
>> > You received this message because you are subscribed to the Google 
>> Groups 
>> > "web2py-users" group. 
>> > To unsubscribe from this group and stop receiving emails from it, send 
>> an 
>> > email to [email protected]. 
>> > For more options, visit https://groups.google.com/groups/opt_out. 
>> > 
>> > 
>>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to