Consider the logic/workflow of this.

When the user selects the first dropdown, the content of the second 
dropdown has to change. How does the server know that you have changed the 
first dropdown? You have not submitted the form yet! This must be handled 
client side using jQuery and perhaps ajax.

Something like this:

jQuery(function(){
   jQuery('#id_first_dropdown').change(function(){
      var selection = jQuery('#id_first_dropdown').val();
      
 
jQuery.post('{{=URL('callbak')}}','value='+escapeURIComponent(selection)).success(function(data){
           jQuery('#id_second_dropdown').html(data);
      });
   });
});

where

def callback():
     value = request.vars.value
     rows = db(db.sometable.somefield==value).select()
     return CAT(*[OPTION(row.someotherfield) for row in rows])

returns the option corresponding to a given value as HTML. You can also use 
json.

On Monday, 7 May 2012 06:09:45 UTC-5, Stefan L wrote:
>
> Not sure I got the heading understandable, but this is what I want to 
> achieve (actual values only for demonstration, the app is not about cars 
> :-)):
>
> Given a table:
> db.define_table('cars', Field('maker','string'), Field('model', 'string'), 
> Field('colour','string'))
> db.cars.maker.requires=IS_IN_SET(('Volvo','VW','Chrysler'))
> db.cars.model.requires=IS_IN_SET(('V50','S60','Passat','Voyager'))
> db.cars.colour.requires=IS_IN_SET(('blue','red','pink'))
>
> How can I present a form to the user where the drop downs depend on each 
> other, i.e. if the user selects a make (Volvo) the next drop down only 
> shows the relevant models (V50, V60) and selecting a model populates the 
> colour drop down with the available choices? I've looked at an example 
> from 
> web2pyslices<http://www.web2pyslices.com/article/show/1410/cascading-drop-down-lists>
>  but 
> in my case I want to store all the choices made (maker, model, colour), not 
> only the final value as in the example (in that case, the area code). 
> Should I be able to adapt the example for my purposes?
>
> Regards,
> /Stefan
>

Reply via email to