Dear all,
I am trying to theme a webform that is loaded with select components.
I would like to theme the individual rows of the answers in a color scheme that applies to all answers. E. g. first row is red, second yellow, third green.
Currently I am only able to theme eith all radio buttons via .form-radios .form-item or every single one of them using identifiers.
To add css classes like "row-1", "row-2", I created a webform-form-tpl.php and successfully added an individual class to the question/item containing the radio buttons by adding
$form['submitted']['my_compontent_name']['#attributes']['class'] = "my_class_name";
What I actually wanted to do is to loop over all components in submitted, find radio buttons and add a alphanumeric classes per question, more or less like
pseudocode:
foreach($form['submitted'] as $c){
if ($c is of type select component) {
int i = 0;
for each $c['radiobutton'] as $sub {
$sub['#attributes']['class'] = row.i++;
}
}
}But I am not sure how to access the individual form items (answer rows/radio buttons) in the component.. Can you help me out here? Thanks!
Comments
Comment #1
vernond commentedYou may find it easier to identify all the bits you need if you install the developer module and enable theme developer also.
Comment #2
quicksketchIn any case, this question is out of scope for the Webform issue queue.
As mentioned in the submission guidelines:
Please refer to other resources such as IRC or Drupal StackExchange to ask your questions.
Comment #3
wickedwookie commentedSorry for that.
Let me document what I did anyways, in case someone else runs into the same trouble.
I approached the issue overring the webform-form.tpl.php template (thanks #1 for setting me back on track). The problem I ran into was that I could only add addtional properties (e. g. classes) to the input control (the radio button). What I needed was rather to add classes to the wrapper class which would have meant to override the module's formattting/display procedures.
What I did instead is rather hackish, but it works. I simply created a loop over the components in the $form['submitted'] object, looking for my components of type 'radio' (sifting through nested arrays to get there). Then I hacked the '#title' property and added the appropriate html tag right in there:
$component['#title']= "<div class=\"row-" . $component['#return_value'] . "\">".$component['#title']."</div>";As my return_values are numeric (as explained above) this gives me the ability to style the options accordingly.