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,805
  • 1
  • 19
  • 25
Nullpoet
  • 10,299
  • 16
  • 47
  • 62
  • 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

12

You can use disabled attribute.

one_or_two = forms.ChoiceField(widget=forms.RadioSelect(attrs={'disabled': 'disabled'}), initial='1') 
karthikr
  • 92,866
  • 25
  • 190
  • 186