Opened 7 years ago

Closed 4 years ago

#12306 closed New feature (wontfix)

Checkbox (label, field) ordering

Reported by: EoghanM Owned by: nobody
Component: Forms Version: 1.1
Severity: Normal Keywords: label checkbox BooleanField
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

It is currently very difficult to reorder the default layout of fields:

<label for="x" ...>My Label:</label> <input id="x".../>

For checkboxes, this should be either:

<input id="x".../> <label for="x"...>My Label</label>

or

<label><input.../> My Label</label>

At the moment, in a template there's no way of knowing if a field is a BooleanField (in order to special case the html), and I don't know how I'd edit widgets etc. to override the current layout.

This has been touched on as a sore point elsewhere:

http://www.mail-archive.com/django-developers@googlegroups.com/msg21887.html

http://stackoverflow.com/questions/572263/


Where would be the best place to apply a patch for this?

  • At the form level: as a new argument to forms/forms.py:_html_output, called 'checkbox_row' which for e.g. table rows would look like:
    u'<tr><td colspan="2">%(field)s%(label)s%(help_text)s%(errors)s</td></tr>'
    
  • At the field level: as a new boolean function 'is_checkbox'?
  • Both of the above?

Change History (6)

comment:1 Changed 7 years ago by Russell Keith-Magee

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedDesign decision needed

I acknowledge the problem, but I'm not sure what the solution should be.

comment:2 Changed 6 years ago by Paul Oswald

You might want to look into this Django library which allows you to override the html of any form field: https://github.com/brutasse/django-floppyforms

More generally, it might make sense to incorporate that library into Django itself to allow users to apply their own markup preferences. It uses the django templating system to define the html and substitutes the field values in. The application creates html5-typed input elements but it could easily be used to output html in the current html 4 style by default. Can someone on the core team can make a call as to if this approach is acceptable?

comment:3 Changed 5 years ago by Matt McClanahan

Severity: Normal
Type: New feature

comment:4 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:5 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:6 Changed 4 years ago by Aymeric Augustin

Resolution: wontfix
Status: newclosed

I'm going to close this for the same reasons as #13401.

The long term solution is indeed something akin to floppyforms, but it hasn't been integrated yet due to performance concerns.

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