First... a little background info.
I tried this....
<?php
/**
* Return a themed form element.
*
* @param element
* An associative array containing the properties of the element.
* Properties used: title, description, id, required
* @param $value
* The form element's data.
* @return
* A string representing the form element.
*
* @ingroup themeable
*/
function [theme]_form_element($element, $value) {
// This is also used in the installer, pre-database setup.
$t = get_t();
/***** MODIFIED CODE *****/
$stripe = ceil($element['#weight']);
if ($stripe % 2) {
$output = '<div class="form-item odd"';
} else {
$output = '<div class="form-item even"';
}
/***** MODIFIED CODE *****/
if (!empty($element['#id'])) {
$output .= ' id="'. $element['#id'] .'-wrapper"';
}
$output .= ">\n";
$required = !empty($element['#required']) ? '<span class="form-required" title="'. $t('This field is required.') .'">*</span>' : '';
if (!empty($element['#title'])) {
$title = $element['#title'];
if (!empty($element['#id'])) {
$output .= ' <label for="'. $element['#id'] .'">'. $t('!title: !required', array('!title' => filter_xss_admin($title), '!required' => $required)) ."</label>\n";
}
else {
$output .= ' <label>'. $t('!title: !required', array('!title' => filter_xss_admin($title), '!required' => $required)) ."</label>\n";
}
}
$output .= " $value\n";
if (!empty($element['#description'])) {
$output .= ' <div class="description">'. $element['#description'] ."</div>\n";
}
$output .= "</div>\n";
return $output;
}
?>
...but it just DIDN'T work. Why??? COLLAPSED FIELDSETS! (sry for the emotion :) They gave me a headache. When you have collapsed fieldsets it screws up the striping. Take my word for it. The "even" / "odd" classes are too many divs in from the parent.
Besides, this method is just not ideal because you DON'T want to have the "even" / "odd" classes inside a child div. You want the parent to have them.
So this is what I did. Sorry, I know it would be much easier if I had patching set up!!!
In webform.module:
<?php
// I added the following function...
/**
* Returns "even" or "odd" by evaluating the element's weight.
*
* @param $weight
* The element's weight. Usually $element['#weight'] or $component['weight'].
*/
function theme_webform_stripe($weight) {
if ($weight % 2) {
return 'odd';
} else {
return 'even';
}
}
?>
<?php
// I added the following lines to webform_theme()
'webform_stripe' => array(
'arguments' => array('weight' => NULL),
),
?>
Then, I opened all the files under the "components" directory and searched each one for "class".
I added theme('webform_stripe', $component['weight']) to every component's class.
I know this is a HORRIBLE way to submit a patch so tomorrow I'm going to figure out the CVS checkout.. patching stuff.
Now, each element/component on the form has an "even" / "odd" class in its highest possible tag (div, fieldset, etc...)! You can even style collapsed fieldsets so your striping doesn't look like it skipped a stripe!
CHEERS!
Comments
Comment #1
bensnyder commentedIs it possible to get this put in?
Comment #2
quicksketchAdding even and odd classes sounds like a good idea. However, there's no way to use this "patch" as-is. You're using a theme over-ride to add the striping, which is fine, but Webform is a module (not a theme) so we can't use this code the way it is.
Comment #3
quicksketchComment #4
bensnyder commentedI think you misread ;)
I initially tried to use theme override but it didn't work properly. I'll create a patch against the latest dev version and submit it when I get a chance.
Comment #5
quicksketchSomething as trivial as striping shouldn't be critical.
Comment #6
quicksketchPlease reopen if a patch can be provided. After 2 years it doesn't seem like this is a high-demand feature.
Comment #7
robhoward79 commentedHow exactly did you do this? I've tried this fix, but can't get it working. I am using D7 though... :S