I have built a multistep webform using webform version 6.2.2 and Drupal 10 and I want to show a summary element on each step that updates with the information of user input from all previous pages.
The summary element is a processed text/HTML element that can be either a single field outside the step wrapper or separate fields inside each step.
What I have tried so far is altering the element in the form validate callback like this:
function THEME_multistep_validate(&$form, \Drupal\Core\Form\FormStateInterface
&$form_state){
if ($form['progress']['#current_page'] == "step_2") {
$form['elements']['step_2']['summary']['#text'] = '<h2>STEP 1 complete</h2>';
}
}
As well as in the wizard_next form action:
function THEME_multistep_step_submit(&$form, \Drupal\Core\Form\FormStateInterface &$form_state)
{
$form['elements']['step_2']['summary']['#text'] = '<h2>STEP 1 complete</h2>';
}
added in the form_alter hook like this:
array_unshift($form['actions']['wizard_next']['#submit'], 'THEME_multistep_step_submit');
In both ways, the form handlers are called and the $form array reflects the changes but the element is still rendered with the initial value and not updated, regardless if the element is outside or inside the steps/pages of the form. Am I missing something here or is there a better approach for this? Any pointers would be greatly appreciated!
Edit: I found this question about a similar problem: https://stackoverflow.com/questions/54582371/drupal-8-webform-how-to-display-text-input-on-one-page-on-the-next-page but the solution is for changing values of actual input fields, wheareas I am trying to change content of a text/HTML element added via the webform UI.