See 
http://stackoverflow.com/questions/8146260/best-practice-for-populating-dropdown-based-on-other-dropdown-selection-in-web2p/8152910#8152910
 for 
links to some other related recipes.

Anthony

On Wednesday, August 29, 2012 3:04:10 AM UTC-4, lyn2py wrote:
>
> Thank you Anthony and Richard, I have tried to use IS_IN_DB in the form of 
> return IS_IN_DB(...) but it doesn't work.
>
> The reason why I am looking for this function is because I am trying to 
> load the options or a second field, based on what is chosen in the first 
> field. Both are SELECTs.
>
> Like this example here:
> http://dev.s-cubism.com/plugin_lazy_options_widget
> but the first field is a select instead of autocomplete.
>
> I am unable to find a function that will return a SELECT field (based on 
> the chosen rows) for the ajax success function.
>
> On Wednesday, August 29, 2012 12:50:13 AM UTC+8, Anthony wrote:
>>
>> Yes. By default, a reference field gets a validator like this: 
>> IS_IN_DB(db, db.sometable._id, db.sometable._format). However, the 
>> IS_IN_DB() validator can take a Set object as the first argument instead of 
>> db, and the list will be based on the records defined by that Set. In that 
>> case, you'll have to explicitly define the validator:
>>
>> requires=IS_IN_DB(db([your query]), db.sometable.id, db.sometable._format
>> )
>>
>> Note, when you define your own validator, you also lose the automatic 
>> "represent" attribute for the reference field, so you might want to set 
>> your own:
>>
>> represent=db.sometable._format
>>
>> Anthony
>>
>> On Tuesday, August 28, 2012 12:28:10 PM UTC-4, lyn2py wrote:
>>>
>>> Hello experts,
>>>
>>> Generally, when we do a SQLFORM, the 'reference table' fields 
>>> automatically gets *all* the available options for choosing as a dropdown 
>>> menu.
>>>
>>> However, I would like to get a filtered list instead of *all* of the 
>>> items. Is there an available function I can use to achieve a filtered list 
>>> for choosing in the dropdown menu?
>>>
>>> Another way to look at this is:
>>> I would like to generate a SELECT/OPTIONS html using a specific query, 
>>> i.e. it uses the retrieved Rows to generate the HTML. I wonder if there is 
>>> a function in web2py for doing this.
>>>
>>> I hope my question is understood. Thank you.
>>>
>>>
>>> PS. If there isn't an available function, I appreciate any tips or 
>>> pointers how I can make this work. Thanks!
>>>
>>

-- 



Reply via email to