I am trying to style CCK fields, but can't do so with checkboxes / radio buttons, as the id selector is not displayed for all radio buttons / checkbox cck fields.
Here's an example of the output of a text_textfield field, with the ID displayed:
<div id="edit-field-garden-size-0-value-1-wrapper" class="form-item"> ... </div>
Here's an example of the output of an optionwidgets_buttons field, with the ID not displayed:
<div class="form-item"> ... </div>
Did anyone have the same issue and a potential solution for this? Thanks.
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | 453400-checkboxes_radios_id.patch | 931 bytes | shp |
| #22 | form.inc_.shp_.patch | 979 bytes | shp |
| #21 | form.inc_.shp_.patch | 816 bytes | shp |
| #20 | form.inc_.patch | 834 bytes | shp |
| #14 | form.inc_.patch | 679 bytes | joelstein |
Comments
Comment #1
yched commentedWe rely on core's radio and checkboxes form elements. Nothing we can do here. I think there's a core issue about that somewhere.
At worst, maybe you can override the form.inc's theme_checkboxes() function in your theme ?
Comment #2
haagendazs commentedThanks for following up. I did more research after this looking in the core section and found a thread here http://drupal.org/node/215301 that has a patch attached with it that fixed the issue.
Comment #3
nancydruThe patch mentioned in #215301: Checkboxes/radios wrapper container does not get an 'id' attribute does not apply any longer. Plus it appears that this is supposedly fixed (form.inc), yet it seems CCK is not providing an ID attribute.
Comment #4
yched commentedFixed in D6 ? Can you point to a thread or commit message showing that ?
Comment #5
nancydruNo, I can't, but if you look at the patch in that thread compared to the code that exists now, you will see a significant change that appears to have attempted to fix this (and didn't).
Comment #6
Alex Andrascu commentedsubscribing...that's an issue
Comment #7
Alex Andrascu commentedand here is the way i solve it...not sure it's properly done but at least got me back on track. Maybe some keen eye should look upon it and make a patch
files edited:
Comment #8
lotyrin commented#7 fixes this issue for me (I have ids now), but an id generated by this change is inconsistent with the ids that work without the change.
For instance, a normal (non optionwidgets) field with a working id on gets "edit-field-field-name-0-value-wrapper", an id on one of the fields that is fixed by #7 gets "field_field_name-wrapper"
Also, this is definitely a core issue, since #7 patches core.
Someone with more familiarity with forms system than I have should decide whether or not this is a duplicate of #215301: Checkboxes/radios wrapper container does not get an 'id' attribute. I haven't tested the patch from that issue (since I believe it only applies to 7).
Comment #9
jteague commentedIn running into this with the latest version of CCK 6.3.x dev, I also needed to add a unique ID wrapper to the radio and check box groups. Taking from #7, I simply inserted this in form.inc at line 2206 in the "function theme_form_element" as a test:
The string replace addition implodes the returned field name (the first child) down to a single 'string'-wrapper. This gets rid of the brackets and other unwanted characters in the string. Of course, you can add hyphens or underscores if you want to break it up into something prettier. For me, I just needed a unique ID. Also, since this test was run on the core, I moved it into hook_alter function in my custom site module.
Comment #10
tmsimont commentedI know this is a lame solution to this issue, but might be the easiest workaround since this remains a problem in the latest D6 release.
I just put the checkbox/radio field inside a fieldgroup without any siblings, you can then target the fieldset group with the "fieldset.group-fieldgroupname " selector and remove the border, legend, etc to make it a invisible wrapper with a unique classname.
Comment #11
nancydruAnd you also put #prefix and #suffix with a div. But that doesn't fix the base problem.
Comment #12
sunBetter title.
As there is no http://api.drupal.org/api/function/form_process_radios/7 in D6, http://api.drupal.org/api/function/theme_radios/6 and http://api.drupal.org/api/function/theme_checkboxes/6 basically need to be adjusted accordingly.
Technically, that unset() just needs to be removed? theme_form_element() appends "-wrapper" to $element['#id'] already.
The patches in #215301: Checkboxes/radios wrapper container does not get an 'id' attribute may contain additional pointers.
Comment #13
joelstein commentedIn case it helps, here's a patch which removes the problematic unset() function.
Comment #14
joelstein commentedOops, here's the patch which affects both checkboxes and radios.
Comment #16
drclaw commentedWhy not just override the theme function? You don't have to change the function in Core to make it work. Just copy the function to your theme's template.php file and change the word 'theme' to whatever your theme is named... Isn't this the whole point of writing theme functions? So people can override them?
Maybe I missed something...
Comment #17
drclaw commentedBy the by, this fixed it for me:
Comment #18
ianchan commented@drclaw - your code was MOST helpful. thank you!
Comment #19
shp commented#14: form.inc_.patch queued for re-testing.
Comment #20
shp commentedOne more patch...
Comment #21
shp commentedComment #22
shp commentedComment #23
lotyrin commentedAny reason why there are three copies of this patch now?
Comment #25
akin.demirci commentedsubscribing...
Comment #26
jvdurme commentedWell, the id is in there now with removing the "unset" line from form.inc.
But can someone tell me how on earth I can add a CSS class to the outer wrapper of the checkboxes div?
When I try adding a new class with hook_form_alter, it only applies to the checkboxes themselves, but not to the outer checkboxes field wrapper.
And if I cannot add a new CSS class to that, I cannot style the label.
thanks.
EDIT: ok nevermind, CSS can be styled by ID also if you use the # tag instead of the . tag in the CSS file
Comment #27
shp commentedComment #28
shp commentedComment #29
dave kopecek@drclaw -- Thanks. Dropped #17 into my template.php and I'm on my way.
Comment #30
fuerst commented#27 works well.
Comment #31
gbirch commented#17 works great for me too (dropped into template.php). One quibble, however:
to made the id format consistent with other form elements, the line
$output .= ' id="edit-'. preg_replace('/\[|\]|_/', '-', str_replace('][', '-', $id[0])) .'value-wrapper"';
should be
$output .= ' id="edit-'. preg_replace('/\[|\]|_/', '-', str_replace('][', '-', $id[0])) .'-value-wrapper"';
(adds a dash between the field name and "value-wrapper")
Comment #32
gábor hojtsy- Was this fixed in Drupal 8/7 already?
- Looks like we purposefully removed the IDs there before. Why?
- As per #31, the resulting ID would not be nice either.
Comment #33
shp commentedIn Drupal 7 it was fixed (I've examined the code and checked on the live site). In D8 the code is almost the same as in D7, so in D8 it is fixed too.
Comment #34
gábor hojtsyHow was it fixed? Where is that issue? Can we be forward compatbile?
Comment #35
shp commentedI meant that in D7/8 the "id" attribute is rendered, but unfortunately I have not found an issue for that.
http://drupal.org/node/444256