Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#6264 closed (invalid)

Field with Choices and radio_admin=True has a bad css class attribute

Reported by: Gregory Taylor <gtaylor@…> Owned by: nobody
Component: Generic views Version: master
Severity: Keywords: generic view, choices, css
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I've defined a model that has a field that looks like this:
comparison_cspace = models.CharField(max_length=3, choices=COMPARISON_CSPACES, radio_admin=True)

I'm using a generic view to render the form, and it's outputting something like this:
<ul class="radiolist inline">

<li>

<input type="radio" id="id_comparison_cspace_0" name="comparison_cspace" value="SPE"/>
<label for="id_comparison_cspace_0">Spectral</label>

</li>
<li>

<input type="radio" id="id_comparison_cspace_1" name="comparison_cspace" value="LAB"/>
<label for="id_comparison_cspace_1">Lab</label>

</li>
<li>

<input type="radio" id="id_comparison_cspace_2" name="comparison_cspace" value="LCH"/>
<label for="id_comparison_cspace_2">LCH</label>

</li>

</ul>

I don't think it's even valid to have spaces in class attributes in css:

class="radiolist inline"

My CSS definition would have to look like:
.radiolist inline { blah }

Which would translate to an element named radiolist that is of tag 'inline', which there is none. It'd be great if the generic view would stick an underscore in there to be like:

class="radiolist_inline"

So I could actually style this :)

Thanks!

Change History (4)

comment:1 Changed 10 years ago by Gregory Taylor <gtaylor@…>

It'd also be really great if the view generated an ID attribute for the <ul> tag as well.

comment:2 Changed 10 years ago by arien

Resolution: invalid
Status: newclosed

A class attribute can specify multiple class names separated by whitespace, see the HTML spec.

In the case of <ul class="radiolist inline"> this means that both the radiolist and the inline class apply to this ul element and both can be use as a selector (see also the CSS 2.1 description of class selectors). Thus, you can style radiolist classes one way, inline classes another and both rulesets will apply to this particular element.

Marking as invalid.

comment:3 in reply to:  1 Changed 10 years ago by arien

As for adding an id attribute to the ul tag, maybe you can use Admin.fields to achieve your aim? (See the model reference)

comment:4 Changed 10 years ago by arien

Ah, and one final comment: this is about the admin interface, not about generic views. :-)

Note: See TracTickets for help on using tickets.
Back to Top