Note that this seems to be a core piece of the webform, so I'm not sure how come nobody else reports it.

Basically if you have a custom webform component (let's say a 2 level select with children choice based on parent choice), and it triggers an AJAX call, you'd expect ajax replaced element retains the values you selected.

The _webform_render_component() hook basically expects input values passed from webform_client_form() function, when the form rebuilds.

The exact value is being passed from this line: https://git.drupalcode.org/project/webform/blob/7.x-4.x/webform.module#L...

        $component_value = isset($input_values[$cid]) ? $input_values[$cid] : NULL;
        _webform_client_form_add_component($node, $component, $component_value, $form['submitted'], $form, $input_values, 'form', $page_num, $filter);

However, the $input_values[$cid] here is always empty. This is because $cid is the "component id", which is something numeric, like 1, 2,3. While the actual $input_values has keys from "form_key", e.g. first_name, last_name etc.

Looking up a few lines it looks like $input_values are initialized from several sources. So I'm not sure if under other situations they are actually using component's $cid instead of form_key.

But from this debug screenshot you can see clearly, in my test case it has form_keys as index.

input values wrong index

Comments

yang_yi_cn created an issue. See original summary.

yang_yi_cn’s picture

Patch

liam morland’s picture

Status: Active » Needs review
liam morland’s picture

What are the steps to reproduce this problem? Maybe something about the custom component is not configured correctly.

liam morland’s picture

Status: Needs review » Closed (outdated)

Drupal 7 is no longer supported. If this applies to a supported version, please re-open.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.