How to disable a choice in django forms ChoiceField

Viewed 176

Here is an exemple of what I have:

forms.py

class aForm(forms.Form):
   choices = [
     ('value1', 'choice1'),
     ('value2', 'choice2'),
     ('value3', 'choice3')
   ]

   dropDownList = forms.ChoiceField(
           choices=choices)

I want to add the attribute Disabledd to the first choice, like this:

<select>
  <option selected value="value1" disabled>choice1</option>
  <option selected value="value2">choice2</option>
  <option selected value="value3">choice3</option>
</select>

How can I add that Disabled attribute from the forms.py file ?

2 Answers

After long search I didn't find the solution am looking for, but I did pass that problem with another aproch, what I did is creating a completly RAW html form from scratch where I had full power so I added the "disabled" attribute to the first option, without touching the views.py file, what I mean is am still using forms.Form and all the validations I already writen, this works by just naming your the fields in the RAW html form the same names as in the Form.

Related