Opened 15 years ago
Closed 11 years ago
#11725 closed New feature (fixed)
Unable to have label tags without a "for" attribute in form widgets
Reported by: | Owned by: | Sergey Kolosov | |
---|---|---|---|
Component: | Forms | Version: | 1.1 |
Severity: | Normal | Keywords: | forms label for none dceu13 |
Cc: | eromijn@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In some cases I want to use a form widget without an input, such as pure javascript or iframe
(recaptcha_django in my case).
form.as_p()
generates a label tag with an unmatched id: <label for="id_recaptcha">
.
This makes my page invalid in HTML5.
I tried to override id_for_label like this in my widget's code:
def id_for_label(self, id_): return None
which gives <label for="None">
.
Anyway, I believe that this case should be treated adequately, because the docstring
states that id_for_label can return None values.
Attachments (2)
Change History (12)
by , 15 years ago
Attachment: | django-label-for-none.patch added |
---|
comment:1 by , 15 years ago
Needs tests: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 14 years ago
This patch has been accepted since Django 1.0, so can it be included mainline ?
I don't want to have to apply this on every release.
by , 14 years ago
Attachment: | django_label_for_none_incl_tests.patch added |
---|
Same patch applied to svn r13303, including tests
comment:4 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → New feature |
comment:7 by , 11 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:8 by , 11 years ago
Needs tests: | unset |
---|
Pull request: https://github.com/django/django/pull/1179
I had to reject tests from the patch above (those were doctests, and those tested a complete form rather than just a label tag).
comment:9 by , 11 years ago
Cc: | added |
---|---|
Keywords: | dceu13 added |
Triage Stage: | Accepted → Ready for checkin |
Looks fine to me. Tests work. I'd like to see it implemented slightly simpler, but because we also don't want a dangling for=""
in the code when there is no ID, I think this is as clean as it gets.
comment:10 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
In be0bab1bb8da80402248cd1fa22fd4cc09b34fe7:
Fixed #11725 -- Made possible to create widget label tag without "for" Thanks Denis Martinez for the report and initial patch, and Sergey Kolosov for bringing the patch up to date.
handle None values from id_for_label