#28712: Add ability to apply separate attributes to ChoiceWidget options
---------------------------------+--------------------------------------
Reporter: Stephen Swatman | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: ChoiceWidget | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Comment (by Stephen Swatman):
Replying to [comment:1 Tim Graham]:
> Could you describe your use case in more detail? Is there a reason that
overriding `ChoiceWidget.create_option()` wouldn't work?
Web developers may want to individually style each option in a
`ChoiceWidget`, be it by adding CSS classes or style attributes. This may
be done to add images to such a widget to make it more appealing to the
user. Developers may also want to add ARIA properties to the options or
add additional information to work with them via JavaScript.
It would absolutely be possible to override the `ChoiceWidget` class and
modifying the `create_option()` method. I imagine, however, that this is a
common enough use case to warrant a simpler method of doing this. Here are
some people on StackOverflow having the same issue:
* https://stackoverflow.com/questions/6477856/how-to-add-attributes-to-
option-tags-in-django
* https://stackoverflow.com/questions/43524214/django-add-attributes-to-
selectmultiple-option-tags
* https://stackoverflow.com/questions/5089396/django-form-field-choices-
adding-an-attribute
--
Ticket URL: <https://code.djangoproject.com/ticket/28712#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/069.61641e80d297b7c0e9ca9e1c59e7bda4%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.