thanks bruno. and thanks for the advice on tuples too.
On 25 May 2011 17:30, "bruno desthuilliers" <bruno.desthuilliers@gmail.com> wrote:
> On May 25, 4:12 pm, Ndungi Kyalo <ndu...@gmail.com> wrote:
>> Am trying to pre-select a radio button created with the django.forms library :
>>
>> choices = forms.ChoiceField(
>> widget = forms.RadioSelect(),
>> choices = [
>> ['a', 'i liked it'],
>> ['b', 'i did not like it']
>> ],
>> required=True
>> )
>>
>> How would I go about getting the 'a' choice pre-selected on an unbound form ?
>
> http://docs.djangoproject.com/en/1.3/ref/forms/api/#dynamic-initial-values
>
> IIRC, this should be enough.
>
> As a side note, you'd better use tuples than lists for your choices -
> at least for the "value, label" pairs which are semantically tuples,
> and possibly for the choices list itself but then it's more of a micro-
> optimisation (tuples are lest costly than lists).
>
> --
> 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+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
-- > On May 25, 4:12 pm, Ndungi Kyalo <ndu...@gmail.com> wrote:
>> Am trying to pre-select a radio button created with the django.forms library :
>>
>> choices = forms.ChoiceField(
>> widget = forms.RadioSelect(),
>> choices = [
>> ['a', 'i liked it'],
>> ['b', 'i did not like it']
>> ],
>> required=True
>> )
>>
>> How would I go about getting the 'a' choice pre-selected on an unbound form ?
>
> http://docs.djangoproject.com/en/1.3/ref/forms/api/#dynamic-initial-values
>
> IIRC, this should be enough.
>
> As a side note, you'd better use tuples than lists for your choices -
> at least for the "value, label" pairs which are semantically tuples,
> and possibly for the choices list itself but then it's more of a micro-
> optimisation (tuples are lest costly than lists).
>
> --
> 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+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment