Problem/Motivation
Were are using a custom submit button on the node edit page which is configured the following:
$element['emp_save_edit_ajax'] = [
'#type' => 'submit',
'#value' => $config->get('button_value'),
'#submit' => [
'::submitForm',
'::save',
],
//'#attributes' => ['class' => 'emp_save_edit_submit_ajax'],
'#attributes' => [
'class' => [
'container-emp_save_edit_submit_ajax',
'button--primary',
],
],
'#ajax' => [
'callback' => '::emp_save_edit_form_submit_ajax',
'progress' => [
'type' => 'throbber',
],
],
'#weight' => $config->get('button_weight'),
'#gin_action_item' => TRUE,
];
Which produces this button html:
<input class="container-emp_save_edit_submit_ajax button--primary button js-form-submit form-submit" form="node-landingpage-content-edit-form" data-drupal-selector="edit-emp-save-edit-ajax" type="submit" id="edit-emp-save-edit-ajax" name="op" value="Save" data-once="drupal-ajax">
When clicking the button the a ajax request is triggered and the server side callback function`emp_save_edit_form_submit_ajax` is called - works.
With tag 3.0-rc14 (and later) the html of the button has changed and the ajax request (and also the server side callback function) is not triggered anymore
new html of button:
<input class="container-emp_save_edit_submit_ajax button--primary button js-form-submit form-submit" data-drupal-selector="gin-sticky-edit-emp-save-edit-ajax" id="gin-sticky-edit-emp-save-edit-ajax" form="node-app-storefront-content-edit-form" data-gin-sticky-form-selector="gin-sticky-edit-emp-save-edit-ajax" type="submit" name="op" value="Save">
I have boiled it down to this commit, with these changes things broke:
https://git.drupalcode.org/project/gin/-/commit/c2d182f5e0d50c8c953eb192...
I have no clue what is going and why things are not working anymore (for us).
May someone can explain
Best regards
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | gin-3499408-custom-ajax-button-reroll-3.x-14.patch | 2.01 KB | aludescher |
Issue fork gin-3499408
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
skrugChanged version from 8.x-3.0-rc14 to 4.0.2 because this also applies for this version but it all started with version 8.x-3.0-rc14.
More precisely with commit https://git.drupalcode.org/project/gin/-/commit/c2d182f5e0d50c8c953eb192...
In other themes ajax button are working as expected.
Other example which does not work:
Comment #5
volkerk commentedComment #6
saschaeggiThis probably needs a rebase since we've merged #3503304: Sticky actions fail on Ajax
Thanks 🙇
Comment #7
miha.wagner commentedCan confirm the patch provided via the MR fixes the ajax button issue. RTBTC +1.
Comment #8
skrugI can also confirm that fix provided in the branch fixes the issue. RTBTC + 1
Thanks everyone.
Comment #10
saschaeggiGlad to see this fixed, thank you! 🥳👏🤝
Comment #11
saschaeggiIncluded in the 4.0.4 release: https://www.drupal.org/project/gin/releases/4.0.4
Comment #13
kmaniThe same issue occurs in Gin 3.0 as well. I'm unable to add my custom AJAX button to the Gin sticky header — the AJAX behavior isn't being attached to the button, and clicking it results in a full page reload.
Comment #14
aludescher commentedHere's the same fix rerolled for Gin 3.x.