summaryrefslogtreecommitdiff
path: root/django/forms
diff options
context:
space:
mode:
authorAnnabelle Wiegart <annabelle.wiegart@proton.me>2026-01-18 20:03:28 +0100
committerJacob Walls <jacobtylerwalls@gmail.com>2026-04-22 17:06:29 -0400
commit63c56cda133a85a158502891c40465bc0331d3d9 (patch)
tree04380903d14307b71416b2e048ce4be8361cf0df /django/forms
parentdc467fdc3b5744cec71fab876c23a14013e2510b (diff)
Fixed #35870 -- Made blank choice label in forms more accessible.
Added new constant django.db.models.fields.BLANK_CHOICE_LABEL for an accessible and translatable blank choice label in forms. Deprecated django.db.models.fields.BLANK_CHOICE_DASH constant. Added the immediately deprecated transitional setting USE_BLANK_CHOICE_DASH. Co-Authored-By: Marijke Luttekes <mail@marijkeluttekes.dev>
Diffstat (limited to 'django/forms')
-rw-r--r--django/forms/fields.py3
-rw-r--r--django/forms/models.py6
2 files changed, 6 insertions, 3 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py
index 8aad2d48b8..26640ed7d3 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -15,6 +15,7 @@ from io import BytesIO
from django.core import validators
from django.core.exceptions import ValidationError
+from django.db.models.utils import get_blank_choice_label
from django.forms.boundfield import BoundField
from django.forms.utils import from_current_timezone, to_current_timezone
from django.forms.widgets import (
@@ -1200,7 +1201,7 @@ class FilePathField(ChoiceField):
if self.required:
self.choices = []
else:
- self.choices = [("", "---------")]
+ self.choices = [("", get_blank_choice_label())]
if self.match is not None:
self.match_re = re.compile(self.match)
diff --git a/django/forms/models.py b/django/forms/models.py
index a53f119995..9686baa6f2 100644
--- a/django/forms/models.py
+++ b/django/forms/models.py
@@ -12,7 +12,7 @@ from django.core.exceptions import (
ValidationError,
)
from django.core.validators import ProhibitNullCharactersValidator
-from django.db.models.utils import AltersData
+from django.db.models.utils import AltersData, get_blank_choice_label
from django.forms.fields import ChoiceField, Field
from django.forms.forms import BaseForm, DeclarativeFieldsMetaclass
from django.forms.formsets import BaseFormSet, formset_factory
@@ -1481,7 +1481,7 @@ class ModelChoiceField(ChoiceField):
self,
queryset,
*,
- empty_label="---------",
+ empty_label="",
required=True,
widget=None,
label=None,
@@ -1508,6 +1508,8 @@ class ModelChoiceField(ChoiceField):
):
self.empty_label = None
else:
+ if empty_label == "":
+ empty_label = get_blank_choice_label()
self.empty_label = empty_label
self.queryset = queryset
self.limit_choices_to = limit_choices_to # limit the queryset later.