# How to disable a choice in django forms ChoiceField

**URL:** <https://forum.djangoproject.com/t/how-to-disable-a-choice-in-django-forms-choicefield/8320>\
**Category:** Using Django\
**Created:** [June 12, 2021, 12:04am UTC](https://forum.djangoproject.com/t/how-to-disable-a-choice-in-django-forms-choicefield/8320 "2021-06-12T00:04:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![0proboy0](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/0proboy0/32/4821_2.png) [@0proboy0](https://forum.djangoproject.com/u/0proboy0)\
**Post date:** [June 12, 2021, 12:04am UTC](https://forum.djangoproject.com/t/how-to-disable-a-choice-in-django-forms-choicefield/8320/1 "2021-06-12T00:04:57Z")

</div>

Here is an exemple of what I have:  
forms.py

```auto
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:

```auto
<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 ?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [June 12, 2021, 12:21am UTC](https://forum.djangoproject.com/t/how-to-disable-a-choice-in-django-forms-choicefield/8320/2 "2021-06-12T00:21:46Z")

</div>

This sounds a lot like an [X/Y problem](https://en.wikipedia.org/wiki/XY_problem) to me. What are you _really_ trying to achieve here? Maybe it will help if you provide a little more background or context to your question.

---

<div class="post-metadata">

**Author:** ![0proboy0](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/0proboy0/32/4821_2.png) [@0proboy0](https://forum.djangoproject.com/u/0proboy0)\
**Post date:** [July 17, 2021, 2:37pm UTC](https://forum.djangoproject.com/t/how-to-disable-a-choice-in-django-forms-choicefield/8320/4 "2021-07-17T14:37:25Z")

</div>

I want to disable (adding the “Disabled” attributre in the Option tag in HTML ) the first Option of the Select box, so that first option will not be clickable (as a title for the Select box), I’ve done it by creating a complete custom form using HTML, I still didn’t find a way to do it using Django

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 17, 2021, 4:33pm UTC](https://forum.djangoproject.com/t/how-to-disable-a-choice-in-django-forms-choicefield/8320/5 "2021-07-17T16:33:40Z")

</div>

At a minimum, you could create a custom template to render the options however you want. The Select widget has an attribute “option\_template\_name” that is used to render the set of options. Alter that attribute on the select widget, then create the template to set the first option as disabled. (The `select_option.html` file is in `django.forms.templates.django.forms.widgets` if you want something to work from.)  
Actually, thinking about it a little more, you might be better off changing the `template_name` attribute, currently referring to `select.html`. It’s _that_ template that iterates over the choices rendering each option. You could create a custom version of that that sets the `disabled` attribute on the first entry.  
Or, in looking at the ChoiceWidget (inherited by Select), it also looks like the `optgroup` attribute within it could be used as well. I’ve never used it this way, but looking at `django.forms.widgets.ChoiceWidget` gives me the impression that you can nest attributes within the values, allowing this to be done without a custom template.

---

<div class="post-metadata">

**Author:** ![0proboy0](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/0proboy0/32/4821_2.png) [@0proboy0](https://forum.djangoproject.com/u/0proboy0)\
**Post date:** [July 17, 2021, 5:04pm UTC](https://forum.djangoproject.com/t/how-to-disable-a-choice-in-django-forms-choicefield/8320/6 "2021-07-17T17:04:18Z")

</div>

thanx for the recomendation, I’ll try them, can you please take a look at that post and see if you can help: [Multi-theme and custom domain name for each user ?](https://forum.djangoproject.com/t/multi-theme-and-custom-domain-name-for-each-user/8823)  
thanx again
