Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cascading forms in Django/else using any Pythonic framework

Tags:

python

django

Can anyone point to an example written in Python (django preferred) with ajax for cascading forms? Cascading Forms is basically forms whose field values change if and when another field value changes. Example Choose Country, and then States will change...

like image 250
user54957 Avatar asked Oct 13 '25 02:10

user54957


1 Answers

This is (mostly) front-end stuff.

As you may have noticed Django attempts to leave all the AJAX stuff up to you, so I don't think you'll find anything built in to do this.

However, using JS (which is what you'll have to do in order to do this without submitting a billion forms manually), you could easily have a django-base view your JS could communicate with:

def get_states(request, country):
    # work out which states are available
    #import simplesjon as sj
    return sj.... 

Then bind your AJAX request to the onchange event of the select (I can't remember if that's right for select boxes) and populate the next field based on the return of the JSON query.

10 minute job with jquery and simplejson.

like image 56
Oli Avatar answered Oct 14 '25 17:10

Oli