#34034: Adding a class on ChoiceWidget subwidgets is excessingly difficult
------------------------------+--------------------------------------
     Reporter:  Claude Paroz  |                    Owner:  nobody
         Type:  New feature   |                   Status:  new
    Component:  Forms         |                  Version:  dev
     Severity:  Normal        |               Resolution:
     Keywords:                |             Triage Stage:  Unreviewed
    Has patch:  0             |      Needs documentation:  0
  Needs tests:  0             |  Patch needs improvement:  0
Easy pickings:  0             |                    UI/UX:  0
------------------------------+--------------------------------------

Comment (by Mark Walker):

 Could you add an example of the difficulty?

 Looking at the `Select` widget
 ([https://github.com/django/django/blob/main/django/forms/widgets.py#L737
 source]), it defines an attribute `multiple`;

 {{{
 #!div style="font-size: 80%"
 Code highlighting:
   {{{#!python
       def get_context(self, name, value, attrs):
         context = super().get_context(name, value, attrs)
         if self.allow_multiple_selected:
             context["widget"]["attrs"]["multiple"] = True
         return context
   }}}
 }}}

 So I'm assuming this then renders with `<select multiple>`. If that's the
 level you want to add a class to, `context["widget"]["attrs"]["class"] =
 "my-select-class"` should then render your classes.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34034#comment:1>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701836f4932e2-f2ac174b-3560-45af-b53f-27386d2948b7-000000%40eu-central-1.amazonses.com.

Reply via email to