After updating from 7.x-3.0 to 7.x-3.4 I noticed that the field required marker (*) gets printed in forms even when the field label is not. I attached two images (before/after) of the issue (the form in the images is coming from Views).
It looks like the algorithm used to determine when the label must be shown has changed from the previous version in the bootstrap_form_element_label() function. Basically, the required marker should be appended to the $title string only if the string is not empty, so the function could return properly.
I'm attaching a patch for the 7.x-3.x branch.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 2638300_required_marker_D7.patch | 1.29 KB | proteo |
| After.png | 8.48 KB | proteo | |
| Before.png | 8.37 KB | proteo |
Comments
Comment #2
proteo commentedComment #4
markhalliwellComment #6
proteo commentedSorry to open this again. The provided patch is working as intended, but I just noticed a small, related bug, which I think could be addressed in the same patch. It's a very small detail, but we're looking for perfection, aren't we?
Today it was brought to my attention that in some cases,
bootstrap_form_element_label()is generating empty<label>elements. It's not very noticeable, only in some edge cases. The problem lies in the line #40:The problem is that
isset()can return true even if$element['#title']is an empty string. In such cases, the line above returns the $title variable as a string containing an space (" "), which is appended afterfilter_xss_admin()in order to visually separate the required marker. In such cases, even if no marker is appended, the evaluation in line #51, which tries to catch empty titles and return, will fail and an empty<label>element will be generated.This is very hard to notice because empty elements usually won't alter the HTML rendering. We noticed today because Webkit browsers seem to be more picky and the combination of this and some unusual CSS in surrounding elements generated additional space which broke the layout.
Suggested fix:
Comment #7
markhalliwellActually, I think it would be better to just add
$titleto the beginning of the condition for$required:Comment #8
proteo commentedSure, that will make it. Just tested on our devel box.
Comment #9
markhalliwellNo actual patch for #7.
Comment #12
markhalliwell