[BangPypers] two dropdowns dependents on each other

Kenneth Gonsalves lawgon at gmail.com
Tue Aug 16 12:27:26 CEST 2011


On Tue, 2011-08-16 at 15:45 +0530, Amit Sethi wrote:
> > without ajax:
> >
> > 1. override __init__ on your modelform, pass the value of the first
> > dropdown to __init__ and populate the second dropdown depending on
> that
> > value. If the value is None, the second dropdown will not be
> populated.
> >
> > 2. in your template, refresh the page when the value of the first
> > dropdown changes.
> >
> There might be a small problem doing this without ajax. While
> reloading, the __init__ of the first form will also  run which will
> bring all user input to default,and thus would require you set the
> values again explicitly instead why not get the values  as json object
> and populate as required using jquery. 

ajax is the way to go - but if you need to learn ajax for it and there
is a deadline ... again depends on what kind of form it is. For bus
booking one can force the user to populate the dropdowns first.
-- 
regards
Kenneth Gonsalves



More information about the BangPypers mailing list