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

RyanPrice’s picture

Assigned: Unassigned » RyanPrice
Status: Active » Needs review
StatusFileSize
new2.32 KB

This is my first attempt at a patch so please let me know if I did anything wrong.

westie’s picture

Patch works well for me, however you need to remove the reference to kpr as if you dont have devel turned on...

RyanPrice’s picture

Thanks westie, thought I got rid of them all but I missed one. Nice catch.

Here it is without the devel line.

RyanPrice’s picture

Here 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).

tedbow’s picture

Version: 7.x-1.0-alpha2 » 7.x-1.x-dev
Status: Needs review » Closed (fixed)

@RyanPriceDotCa, thanks for the patch I committed this to the 7 dev branch.

tedbow’s picture

Status: Closed (fixed) » Patch (to be ported)

@RyanPriceDotCa if you have time this needs to be ported to the 6.x branch

westie’s picture

Ported RyanPriceDotCa 7.x-1.x patch to 6.x-1.x

RyanPrice’s picture

Thanks westie, much appreciated.

tedbow’s picture

@RyanPriceDotCa or @westie the D6 patch no longer applies. Could you re-roll?
Thanks

densolis’s picture

Issue tags: +waiting-for-user

Hi,

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

tedbow’s picture

Status: Patch (to be ported) » Postponed (maintainer needs more info)

Postponing this until it can be re-rolled by someone against the dev version.

tedbow’s picture

Status: Postponed (maintainer needs more info) » Needs work

Actually should be "needs work"