Opened 12 years ago
Closed 12 years ago
#22533 closed New feature (fixed)
Allow overriding `label_suffix` on a per-field basis
| Reported by: | julen | Owned by: | julen |
|---|---|---|---|
| Component: | Forms | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Django 1.6 onwards, BoundField.label_tag now includes form's label_suffix.
The docs mention that "You can also customize the label_suffix on a per-field basis using the new label_suffix parameter on label_tag()".
In order to customize this on a per-field basis, you'd use {{ field|label_tag:"=" }} from templates, where label_tag is a custom template filter which would return field.label_tag(label_suffix='=') for this example.
Since this is not an attribute stored by each field, you can only override it if you are manually rendering fields. This is not convenient if you are using other shortcuts such as {{ form.as_p }} — there's no way you can override the label_suffix on a per-field basis in that scenario.
I'd suggest to store label_suffix for each field, so it could be set when you instantiate the field as part of a form. BoundField.label_tag would then be able to be properly customized on a per-field basis. It would use:
label_suffixfrom the keyword arguments, specified at run-time. If this isNone,self.label_suffix, defined when adding the field to a form. If this isNone,self.form.label_suffix, defined when instantiating the form.
Change History (6)
comment:1 by , 12 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|---|
| Type: | Uncategorized → New feature |
| Version: | 1.6 → master |
comment:2 by , 12 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:3 by , 12 years ago
| Has patch: | set |
|---|
comment:4 by , 12 years ago
The patch is in very good shape. A second pass by a native speaker would be nice for the docs/spelling (I've seen trully -> truly).
comment:5 by , 12 years ago
I've just fixed the spelling mistake and rebased master onto the branch (the PR has been updated).
comment:6 by , 12 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
PR available for review at:
https://github.com/django/django/pull/2616