Created
November 3, 2017 12:03
-
-
Save alexey-kuznetsov/279dd42c293bae45fc000fb32842db57 to your computer and use it in GitHub Desktop.
Working ajax form with multiple commands in response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* AJAX process step | |
*/ | |
public function processStep(array &$form, FormStateInterface $form_state) { | |
$ajax_response = new AjaxResponse(); | |
$ajax_response->addCommand(new ReplaceCommand( | |
'h1.page-title', | |
'<h1 class="page-title">' . $this->getTitle() . '</h1>' | |
)); | |
// This is necessary to attach settings | |
$elements = $form; | |
\Drupal::service('renderer')->renderRoot($elements); | |
$ajax_response->addCommand(new SettingsCommand( | |
$elements['#attached']['drupalSettings'], | |
TRUE | |
)); | |
$ajax_response->addCommand(new ReplaceCommand( | |
'#stepped-search-wrapper', | |
\Drupal::service('renderer')->renderRoot($form) | |
)); | |
return $ajax_response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment