(self, attrs, widget=None)
| 270 | return self.form.get_initial_for_field(self.field, self.name) |
| 271 | |
| 272 | def build_widget_attrs(self, attrs, widget=None): |
| 273 | widget = widget or self.field.widget |
| 274 | attrs = dict(attrs) # Copy attrs to avoid modifying the argument. |
| 275 | if ( |
| 276 | widget.use_required_attribute(self.initial) |
| 277 | and self.field.required |
| 278 | and self.form.use_required_attribute |
| 279 | ): |
| 280 | # MultiValueField has require_all_fields: if False, fall back |
| 281 | # on subfields. |
| 282 | if ( |
| 283 | hasattr(self.field, "require_all_fields") |
| 284 | and not self.field.require_all_fields |
| 285 | and isinstance(self.field.widget, MultiWidget) |
| 286 | ): |
| 287 | for subfield, subwidget in zip(self.field.fields, widget.widgets): |
| 288 | subwidget.attrs["required"] = ( |
| 289 | subwidget.use_required_attribute(self.initial) |
| 290 | and subfield.required |
| 291 | ) |
| 292 | else: |
| 293 | attrs["required"] = True |
| 294 | if self.field.disabled: |
| 295 | attrs["disabled"] = True |
| 296 | if not widget.is_hidden and self.errors: |
| 297 | attrs["aria-invalid"] = "true" |
| 298 | # Preserve aria-describedby provided by the attrs argument so user |
| 299 | # can set the desired order. |
| 300 | if not attrs.get("aria-describedby") and not self.use_fieldset: |
| 301 | if aria_describedby := self.aria_describedby: |
| 302 | attrs["aria-describedby"] = aria_describedby |
| 303 | return attrs |
| 304 | |
| 305 | @property |
| 306 | def aria_describedby(self): |
no test coverage detected