I'm trying to open a webform in a modal by using OpenModalDialogCommand
in an AjaxResponse
like this.
- in
buildForm
method, I'm specifying AJAX callback like this:
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Send'),
'#ajax' => [
'callback' => [$form_state->getFormObject(), 'ajaxSubmitForm'],
'disable-refocus' => TRUE,
'progress' => 'none',
],
];
- in
ajaxSubmitForm
, I'm specifyingAjaxResponse
like this:
$output['webform'] = [
'#type' => 'webform',
'#webform' => 'contact',
'#default_data' => [],
];
$response->addCommand(new OpenModalDialogCommand(
'My title',
$output,
[
'width' => '600px',
'dialogClass' => 'social-dialog--task-webform',
]
));
return $response;
This works fine, but the action
attribute of the <form>
rendered in the modal is set to the path of the page, instead of the webform. Which results in HTML being returned in the AJAX response and the Drupal.AjaxError
in the browser console. How can I fix this?
EDIT: I noticed, that views_ui
core module defines a SetFormCommand, which allows for custom URL used when views form is displayed in the modal. Isn't something like this also needed for webform forms?
EDIT 2: So I tried to reimplement SetFormCommand
for webform, but it's not working. Perhaps I'm limited by my insufficient knowledge of AJAX API in Drupal here.
OpenModalDialogCommand
yet but found this link check once .. hope will be helpful.