Closed (fixed)
Project:
Webform
Version:
6.x-3.2
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
10 Sep 2010 at 08:46 UTC
Updated:
28 Feb 2011 at 23:46 UTC
In Webform 2, I managed to create a list of radiobuttons with date components for each option. I did this by creating a 'radios'-element for each option, grouping them with the attribute #parents.
Example code:
$form['option_one'] = array(
'#type' => 'radios',
'#options' => array('0' => t("Exact date:")),
'#weight' => 22,
'#parents' => array('mygroup'),
);
$form['option_one_date'] = array(
'#type' => 'date_select',
'#attributes' => array('class'=>'marginleft-20'),
'#date_format' => 'd-F-Y',
'#date_year_range' => '0:+5',
'#date_label_position' => 'none',
'#weight' => 23,
);
$form['option_two'] = array(
'#type' => 'radios',
'#options' => array('1' => t("Approximately:")),
'#weight' => 24,
'#parents' => array('mygroup'),
);
$form['option_two_date'] = array(
'#type' => 'date_select',
'#attributes' => array('class'=>'marginleft-20'),
'#date_format' => 'd-F-Y',
'#date_year_range' => '0:+5',
'#date_label_position' => 'none',
'#weight' => 25,
);
$form['option_three'] = array(
'#type' => 'radios',
'#options' => array('2' => t("I'm not sure")),
'#weight' => 26,
'#parents' => array('mygroup'),
);
Look at the attachment to see the result of this code.
In Webform 3.2, it seems like the possibility to group items through #parents is not possible anymore.
How can I achieve this in Webform 3.2?
| Comment | File | Size | Author |
|---|---|---|---|
| webform2-date-inside-list.jpg | 9.21 KB | adriaanm |
Comments
Comment #1
quicksketchI'm not sure how you're doing this creation of elements, theming, hook_form_alter(), PHP in a textarea? I generally do not provide support on how to write custom code in the Webform issue queue.
Comment #2
adriaanm commentedI have a modules that provides a block. The block prints this form variable using drupal_get_form.
Comment #3
adriaanm commentedIt looks like this would we possible if Field Key is not required to be unique for select options with only one option.
In that way, you could define multiple "select options"-fields with the same field key, resulting in a multiple radios-element with the same parents.
Comment #4
quicksketchIf wanting to do the layout of your form in a custom manner, you should theme your form as described in THEMING.txt. Then you can drupal_render() out the individual radio buttons and date fields.
Comment #5
quicksketch