Opened 2 years ago

Closed 2 years ago

#20655 closed Cleanup/optimization (wontfix)

CheckboxSelectMultiple renders an empty ul when there are no choices

Reported by: caroline@… Owned by: nobody
Component: Forms Version: 1.5
Severity: Normal Keywords:
Cc: bmispelon@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

This is particularly pertinent in the case of ModelChoiceField, where it may be desired that there are not yet any choices, and a '<ul></ul>' in the source code messes up the rendering.

This is caused in django.forms.widgets, line 759.

I propose to delete lines 759 and 777 and on line 777:

if len(output):

output.insert(0, '<ul>')
output.append('</ul>')

Change History (3)

comment:1 Changed 2 years ago by caroline@…

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from CheckboxSelectMultiple renders an empty widget when there are no choices to CheckboxSelectMultiple renders an empty ul when there are no choices

comment:2 Changed 2 years ago by caroline@…

  • That should say and "<ul></ul>" in the final HTML messes up the display of the form.

comment:3 Changed 2 years ago by bmispelon

  • Cc bmispelon@… added
  • Component changed from Uncategorized to Forms
  • Resolution set to wontfix
  • Status changed from new to closed
  • Type changed from Bug to Cleanup/optimization

Hi,

An empty <ul> is valid markup so it shouldn't mess up the displaying of a form.
This might be a CSS issue instead.

I'm -1 on the idea of changing the behavior of CheckboxSelectMultiple for the following reasons:

1) Backwards compatibility issues: we can't simply change this behavior since other users are probably relying on it.
2) Consistency with other widgets: a Select widgets renders as an empty <select> when its choices are empty, not an empty string.
3) It shouldn't be hard to implement a custom widget if you wanted this behavior. With the refactor introduced in commit 9ac4dbd7b53d187ca54f28e247d3a120660938ca, all you'd need to do would be to write a custom renderer for the widget.

For these reasons, I'm going to close this as wontfix.
Don't hesitate to reopen this ticket if you disagree with me and if you have arguments that address the concerns I've raised.
There's also the django-developers mailing list where you can start a discussion about this issue: http://groups.google.com/group/django-developers.

Thanks.

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