When embedding a multi-page webform within a render array using #type => 'webform', it seems like there's a bug where the conditional logic of webform elements does not work.
Note: The webform's conditional logic does work when I view the webform in webform's actual "View" and "Test" pages.
Furthermore, when embedding a webform on a page using a block, the conditional logic also works (but the page refreshes between the page).
On a side note, when embedding the multi-page webform in a form (using the code below), the page isn't refreshed.
Here's my webform yaml:
...
elements: |-
page_1:
'#type': webform_wizard_page
'#title': 'Page 1'
show_textbox:
'#type': checkbox
'#title': 'Show textbox'
textbox:
'#type': textarea
'#title': Textbox
'#states':
visible:
':input[name="show_textbox"]':
checked: true
page_2:
'#type': webform_wizard_page
'#title': 'Page 2'
show_textbox2:
'#type': checkbox
'#title': 'Show textbox'
textbox2:
'#type': textarea
'#title': Textbox
'#states':
visible:
':input[name="show_textbox2"]':
checked: true
...
Also, here's the Drupal Form class I'm using to embed the webform:
<?php
namespace Drupal\test_webform_conditionals\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
class TestForm extends FormBase
{
public function getFormId()
{
return 'test_webform_conditionals';
}
public function buildForm(array $form, FormStateInterface $form_state)
{
$form['#tree'] = TRUE;
$form['webform'] = [
'#type' => 'webform',
'#webform' => 'test_conditionals', // webform id goes here
'#lazy' => TRUE // If this is false, conditionals won't work at all. When it's true, at least the conditionals only work for the elements in the first page of the webform. But the conditional logic for the elements on the second and further pages won't work
];
return $form;
}
public function validateForm(array &$form, FormStateInterface $form_state)
{
}
public function submitForm(array &$form, FormStateInterface $form_state)
{
}
}
Am I doing something wrong when embedding a multi-page webform with conditional logic?
Thanks!