Drupal / jQuery / CSS :: Wrap radio button label in span tag?
When a radio button is rendered in Drupal, it comes out like:
<label class="form-radio" for="sample">
<input type="radio" name="samp" value="1" />Sample
</label>
I've been looking at theming functions (namely, theme_radios and theme_form_element, but can't figure out how to render the ou开发者_运维知识库tput like
<label class="form-radio" for="sample">Sample</label>
<input type="radio" name="samp" value="1" />.
Can someone point me in the right direction? Been combing the forums but haven't found anything to help... I'd even be happy with a jquery solution...
It sounds like you were close—the function theming a single radio input is theme_radio (not theme_radios, which exists but is different).
To do this, create an override function in your theme's template.php based on theme_radio, i.e.
<?php
function mytheme_radio($element) {
_form_set_class($element, array('form-radio'));
$output = '<input type="radio" ';
$output .= 'id="' . $element['#id'] . '" ';
$output .= 'name="' . $element['#name'] . '" ';
$output .= 'value="' . $element['#return_value'] . '" ';
$output .= (check_plain($element['#value']) == $element['#return_value']) ? ' checked="checked" ' : ' ';
$output .= drupal_attributes($element['#attributes']) . ' />';
if (!is_null($element['#title'])) {
$output = '<label class="option" for="' . $element['#id'] . '">' . $element['#title'] . '</label>' . $output;
}
unset($element['#title']);
return theme('form_element', $element, $output);
}
?>
(This works for any of the theme functions found in /includes/form.inc; remember to name the override function after your theme.) Assuming you're using Drupal 6 based on the link you sent.
You can try this after the page is loaded
$(function(){
$("lable.form-radio").each(function(){
$(this).after($(this).find("input[name=samp]"));
});
});
Another solution for question "How to styling by css input radios inside the label?" For Bootstrap theme its problem)) We can wrap radio label' title in this file:
sites/all/themes/bootstrap/templates/system/form-element-label.func.php
In lines with $output
add to $title
span tag line 70, 80, 89
e.g. $output .= '<span>' . $title . '</span>';
3 days for seeking answer))
精彩评论