7
class MyForm(forms.Form):
    CHOICES = (('1', 'one',), ('2', 'two',))
    one_or_two = forms.ChoiceField(widget=forms.RadioSelect, initial='1') 

def show(request):   
    form = MyForm()   
    # render form

How to make the field one_or_two readonly ?

horns
  • 1,843
  • 1
  • 19
  • 26
Nullpoet
  • 10,949
  • 20
  • 48
  • 65
  • Have you tried looking at this? http://stackoverflow.com/questions/324477/in-a-django-form-how-to-make-a-field-readonly-or-disabled-so-that-it-cannot-b – Amit Sep 26 '12 at 18:55
  • Yes, it doesn't work for me. I am extending forms.Form unlike ModelForm as in the pointed question. – Nullpoet Sep 26 '12 at 19:02

1 Answers1

11

You can use disabled attribute.

one_or_two = forms.ChoiceField(widget=forms.RadioSelect(attrs={'disabled': 'disabled'}), initial='1') 
karthikr
  • 97,368
  • 26
  • 197
  • 188