0

I am trying to create dependent dropdowns following this link: http://www.devinterface.com/blog/en/2011/02/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/

But I have this form:

class FrequencyForm(CityForm)
    def __init__(self, *args, **kwargs):
        super(FrequencyForm, self).__init__(*args, **kwargs)
        self.frequency_list = [('-1','None')]
        self.fields['term'] = forms.ChoiceField(choices=self.frequency_list, required=True, widget=forms.RadioSelect())

I don't want the default value to appear when the list populates. What should I do?

blackmamba
  • 1,952
  • 11
  • 34
  • 59

1 Answers1

0

In

self.fields['term'] = forms.ChoiceField(choices=self.frequency_list, required=True, widget=forms.RadioSelect())

self.frequency_list is a list of tuples. As far as I can see there is only one choice for your dropdown i.e [('-1','None')]. Try putting an entry at first index in this list, for eg.

[('','None'),('-1','None')]

and now the first one will become the default selected element.

For more you can refer this : Setting the selected value on a Django forms.ChoiceField

Community
  • 1
  • 1
darxtrix
  • 2,032
  • 2
  • 23
  • 30