Created
May 15, 2019 13:45
-
-
Save gerzenstl/afaf4ff56cde4e53ffc6d1afce8c254b to your computer and use it in GitHub Desktop.
Custom ajax progress indicator for Drupal 8
This file contains hidden or 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
| (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"> </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); |
This file contains hidden or 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
| $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