mirror of
https://github.com/django/django.git
synced 2025-03-06 07:22:32 +00:00
Fixed #34705 -- Reallowed BoundField.as_widget()'s attrs argument to set aria-describedby.
Regression in 966ecdd482167f3f6b08b00f484936c837751cb9.
This commit is contained in:
parent
e5e9699e0f
commit
3f73df44f2
@ -287,12 +287,15 @@ class BoundField(RenderableFieldMixin):
|
|||||||
attrs["required"] = True
|
attrs["required"] = True
|
||||||
if self.field.disabled:
|
if self.field.disabled:
|
||||||
attrs["disabled"] = True
|
attrs["disabled"] = True
|
||||||
# If a custom aria-describedby attribute is given and help_text is
|
# If a custom aria-describedby attribute is given (either via the attrs
|
||||||
# used, the custom aria-described by is preserved so user can set the
|
# argument or widget.attrs) and help_text is used, the custom
|
||||||
# desired order.
|
# aria-described by is preserved so user can set the desired order.
|
||||||
if custom_aria_described_by_id := widget.attrs.get("aria-describedby"):
|
if (
|
||||||
attrs["aria-describedby"] = custom_aria_described_by_id
|
not attrs.get("aria-describedby")
|
||||||
elif self.field.help_text and self.id_for_label:
|
and not widget.attrs.get("aria-describedby")
|
||||||
|
and self.field.help_text
|
||||||
|
and self.id_for_label
|
||||||
|
):
|
||||||
attrs["aria-describedby"] = f"{self.id_for_label}_helptext"
|
attrs["aria-describedby"] = f"{self.id_for_label}_helptext"
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
|
@ -3082,6 +3082,17 @@ Options: <select multiple name="options" required>
|
|||||||
"</span></td></tr>",
|
"</span></td></tr>",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_as_widget_custom_aria_describedby(self):
|
||||||
|
class FoodForm(Form):
|
||||||
|
intl_name = CharField(help_text="The food's international name.")
|
||||||
|
|
||||||
|
form = FoodForm({"intl_name": "Rendang"})
|
||||||
|
self.assertHTMLEqual(
|
||||||
|
form["intl_name"].as_widget(attrs={"aria-describedby": "some_custom_id"}),
|
||||||
|
'<input type="text" name="intl_name" value="Rendang"'
|
||||||
|
'aria-describedby="some_custom_id" required id="id_intl_name">',
|
||||||
|
)
|
||||||
|
|
||||||
def test_subclassing_forms(self):
|
def test_subclassing_forms(self):
|
||||||
# You can subclass a Form to add fields. The resulting form subclass will have
|
# You can subclass a Form to add fields. The resulting form subclass will have
|
||||||
# all of the fields of the parent Form, plus whichever fields you define in the
|
# all of the fields of the parent Form, plus whichever fields you define in the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user