- Issue created by @altcom_neil
- last update
about 1 year ago 29,477 pass - last update
about 1 year ago Custom Commands Failed - 🇬🇧United Kingdom altcom_neil
I guess I have found why this hasn't been done before. It is not the simple case of adding the support to initiate the callbacks to use GET instead of POST by mimicking what was done for links.
While it looks like all the JavaScript libraries are being added to the AjaxResponse object, the
add_js: function add_js(ajax, response, status)
call in core/mis/ajax.js throws the "LoadJS" error from the core/assets/vendor/loadjs/loadjs.min.js file when attempting to load any libraries that weren't already loaded.In our case we were creating a form with an ajax field with a url:
// Origin $form['origin'] = [ '#type' => 'select', '#title' => $this->t('Origin'), '#options' => ['' => '- Choose -'] + $origins '#required' => true, '#attributes' => [ 'class' => [ 'no-error', ], 'data-ajax-type' => 'get', ], '#ajax' => [ 'disable-refocus' => TRUE, // Or false to re-focus on the triggering element. 'event' => 'change', 'progress' => [ 'type' => 'throbber', 'message' => $this->t('Updating ...'), ], 'url' => Url::fromRoute('custom_module.origin_callback.get'), 'options' => ['query' => ['ajax_form' => 1]], ], ];
The Controller for this route then updated a second select field with a list destinations with a ReplaceCommand, and returned a MessageCommand. It is the 'core/drupal.message' library that is in the list of attached libraries with the AjaxResponse but throws the error trying to load it. Which then leads to a further js error when the message call
message: function message(ajax, response)
tries to call 'new Drupal.Message()'.This could be a trivial or a complicated fix requiring more patches, I don't have any familiarity with any of the Ajax system, nor the time to investigate any further so will have to give up on adding this functionality for now.
- last update
about 1 year ago 30,341 pass