I'm spent hours reading docs and Googling for the solution to this problem to no avail. Running Django 1.1 with mod_wsgi
I have a Form with a ChoiceField where the choices are established by reading them from the database. Then I try to initialize the initial selected choice so it will be "selected" in the HTML. But nothing I tried works. As you can see below I set the initial value for the field in the FormSet call. I also set it in the Form class just to see if it'll take. No matter what, there is no selected field in the output html. The options in the <select> are correct, but never is one of them selected. class PhoneForm(forms.Form): telephoneType = forms.ChoiceField(required=True,choices=[]) def __init__(self, *args, **kwargs): super(forms.Form, self).__init__(*args, **kwargs) choices = TelephoneType.objects.all() tt = [] i = 0 for c in choices: i = i + 1 tt.append((i,c.telephone_type)) self.fields['telephoneType'].choices = tt self.fields['telephoneType'].initial = 2 PhoneFormSet = formset_factory(PhoneForm, extra=1, can_delete=True) phones = get_phones(person_id) phoneData = [] for t in phones: tt = TelephoneType.objects.get (telephone_type=t.telephone_type) do = tt.display_order phoneData.append({'telephoneType': do}) phone_formset = PhoneFormSet(initial=phoneData) logging.debug(str(phone_formset)) return phone_formset --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---