I have a form with 2 select boxes that I load into a template.
Initially the "mailing country" choice is loaded with all available
countries and the "mailing states" is empty because a country hasn't
been selected yet.  When a user selects a "mailing country" choice, I
want all the states from that country to populate in the "mailing
state" choice box.  I know this is all possible with javascript on the
fly, but I would rather not code it that way.  I have tried posting
the information back to the same page once the user changes the select
box, but if the user has any errors those are displayed too.  Can I
somehow reload the page and keep the information that was previously
there, and then restrict the errors from being shown.

Here is my code:
---------------------
--FORMS.PY--
---------------------
class CustomerAdd(forms.Form):
    ....
    mailing_country =
forms.ChoiceField(widget=forms.Select(attrs={'onChange':'country_change()'}),
choices=StaticCountries().GetListForSelect(), label=u'Mailing
Country', required=False)

    mailing_state =
forms.ChoiceField(choices=StaticRegions().GetListForSelect(None),
label=u'Mailing State', required=False)
    ....
--------------------
--VIEWS.py---
---------------------
def customer_add_view(request):
    if request.method == 'POST':
        form = CustomerAdd(request.POST)
        """
        if form.is_valid():
            entry = form.save(commit=False)
            entry.save()
            return HttpResponseRedirect("/")
        """
    else:
        form = CustomerAdd()
    t = loader.get_template('customer/new_customer.html')
    c = Context({
        'form': form,
        'is_valid':form.is_valid()
    })
    return HttpResponse(t.render(c))
------------------------------
----TEMPLATE.PY---
------------------------------
<script language="javascript">
function country_change(){
  document.forms[0].method = "get";
  document.forms[0].submit();
}
</script>
<form action="." method="post">
{{test}}<br>
<table>
<tr>
<td>{{form.mailing_country.label}}</td><td>{{form.mailing_country}}</
td><td>{{form.mailing_country.errors}}</td>
</tr>
<tr>
<td>{{form.mailing_state.label}}</td><td>{{form.mailing_state}}</
td><td>{{form.mailing_state.errors}}</td>
</tr>
</table>
<input type="submit" value="Save" />
</form>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to