Steps to reproduce:
1. Create a basic form with a yes/no question to start.
2. Create a fieldset, we'll call it fieldset 'A'. Make this fieldset conditional on step 1 being 'Yes'.
3. Create a grid type within fieldset A, populate it with a few options and questions, make sure its required.
4. Try submitting the form with step 1 answer set to 'No'.
You'll get errors saying the questions in the grid are required.
I've traced it to this function:
/**
* When the form is being built AFTER it is submitted then this function will make components that were hidden not required
* @param $form_element
* @param $form_state
*
* @return boolean
*/
function webform_conditional_element_after_build($form_element, &$form_state) {
//only do this when the form is being submitted NOT displayed
if (!empty($form_state['input'])) {
$submitted_values = _webform_conditional_get_submitted_values($form_state);
//load the components into a flattened array
$components = _webform_conditional_get_all_components($form_element['#webform_component']['nid'], $submitted_values);
$was_hidden = _webform_conditional_was_hidden($form_element['#webform_component']['cid'], $components);
if ($was_hidden) {
$form_element['#required'] = FALSE;
_webform_condtional_clear_element_values($form_element);
}
}
return $form_element;
}was_hidden will function properly, but there are sub-arrays in $form_element that need to have their #required value set to false. It's tricky to identify them as the array names are the keys to the questions, so it will be different to everyone.
My recommended solution would be to cycle through the form_element recursively when the type is 'webform_grid' and set all '#required' keys to FALSE. This might also require a special case in _webform_condtional_clear_element_values(&$elements) for webform_grid that would do a similar thing for clearing values.
Will attempt a patch and post shortly.
Comments
Comment #1
RyanPrice commentedThis is my first attempt at a patch so please let me know if I did anything wrong.
Comment #2
westie commentedPatch works well for me, however you need to remove the reference to kpr as if you dont have devel turned on...
Comment #3
RyanPrice commentedThanks westie, thought I got rid of them all but I missed one. Nice catch.
Here it is without the devel line.
Comment #4
RyanPrice commentedHere is the most up to date patch. This takes 7.x-1.0-alpha2 and does the following:
- adds support for the webform_grid type
- adds support for the select_or_other type (created by http://drupal.org/project/select_or_other)
- formatted using NetBeans to match up to Drupal Coding standards (http://drupal.org/coding-standards).
Comment #5
tedbow@RyanPriceDotCa, thanks for the patch I committed this to the 7 dev branch.
Comment #6
tedbow@RyanPriceDotCa if you have time this needs to be ported to the 6.x branch
Comment #7
westie commentedPorted RyanPriceDotCa 7.x-1.x patch to 6.x-1.x
Comment #8
RyanPrice commentedThanks westie, much appreciated.
Comment #9
tedbow@RyanPriceDotCa or @westie the D6 patch no longer applies. Could you re-roll?
Thanks
Comment #10
densolis commentedHi,
I am helping Ted with this issue. We never received a reply from the above request (Can you re-roll?). What is the status of this request?
Thanks,
Dennis
Comment #11
tedbowPostponing this until it can be re-rolled by someone against the dev version.
Comment #12
tedbowActually should be "needs work"