Skip to content

Instantly share code, notes, and snippets.

@gerzenstl
Created May 15, 2019 13:45
Show Gist options
  • Select an option

  • Save gerzenstl/afaf4ff56cde4e53ffc6d1afce8c254b to your computer and use it in GitHub Desktop.

Select an option

Save gerzenstl/afaf4ff56cde4e53ffc6d1afce8c254b to your computer and use it in GitHub Desktop.
Custom ajax progress indicator for Drupal 8
(function ($, window, Drupal, drupalSettings) {
// We define our the template for the progress indicator.
Drupal.theme.ajaxProgressMyCustomSpinner = function (message) {
var message = message || '';
var spinner = '<div class="throbber">&nbsp;</div>';
return '<div class="ajax-progress ajax-progress-spinner">' + spinner + message + '</div>';
};
// We define the progress indicator to include it on the form
Drupal.Ajax.prototype.setProgressIndicatorMyCustomSpinner = function () {
this.progress.element = $(Drupal.theme('ajaxProgressMyCustomSpinner', this.progress.message));
$(this.element).after(this.progress.element);
};
})(jQuery, window, Drupal, drupalSettings);
$form['test_button'] = [
'#type' => 'submit',
'#value' => $this->t('Save'),
'#ajax' => [
'callback' => 'mymodule_ajax_callback',
'progress' => [
'type' => 'mycustomspinner',
'message' => 'My custom message',
],
'wrapper' => 'js_ajax_test_form_wrapper',
],
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment