Opened 8 years ago

Closed 8 years ago

#4975 closed (fixed)

Colons: Always appended to labels

Reported by: rtconner Owned by: nobody
Component: Forms Version: master
Severity: Keywords: newforms forms
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Hi, I wanted to make a form, but I didn't want the labels to have colons. After some looking I figured I'd have to make myself a generator. But after looking, even making my own generator does not get rid of the colons. My own generator would use _html_output which always appends colons (except where there is punctuation).

That is not very flexible. Can you move the colons into as_table, as_ul, so they can be made to be optional. Or perhaps make some label formatting function within BaseForm which I can override when I would want to.

Thanks. And yes Django still rocks.

Attachments (2)

label_colon_removal.patch (90.3 KB) - added by gnuvince 8 years ago.
configurable_suffix.patch (5.4 KB) - added by gnuvince 8 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 8 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

I was thinking, another way to do this is to make a labelSuffix attribute on BaseForm. By default the value could be a colon. If its set to None there would be no colon appended. If I changed it to a dash a dash would be appended.

comment:2 Changed 8 years ago by SmileyChris

  • Triage Stage changed from Unreviewed to Design decision needed

It's come up before and the answer has been "don't use _html_output", but I think that perhaps there's a place for a label_tag_func function on BaseForm.

It would also allow for things like building a label which says "Email (optional):"

The default func would look something like:

def label_tag_func(bf):
    label = escape(force_unicode(bf.label))
    # Only add a colon if the label does not end in punctuation.
    if label[-1] not in ':?.!':
        label += ':'
    return label

Changed 8 years ago by gnuvince

comment:3 Changed 8 years ago by gnuvince

  • Has patch set

I've added a (rather large) patch to fix the issue. The patch remove the code that adds the colon from forms.py and the rest of the patch is to fix the test cases.

comment:4 Changed 8 years ago by mtredinnick

Removing the default colon is not an option. Making it configurable (whether or not to include it) is a possibility, though.

comment:5 Changed 8 years ago by gnuvince

I reworked the issue and I have developed a patch to make it possible to configure the suffix character on a per-form basis.

Changed 8 years ago by gnuvince

comment:6 Changed 8 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(In [6352]) Fixed #4975 -- Allow the default label suffix character to be configured. Thanks, Vincent Foley.

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