1

I have the weird problem that an Ajax enabled form that just worked stopped working - and I have not a clue what is causing this and when it stopped to work. The form itself has no changes for months now and I did not find any code updates which may interfere with this form.

The form is defined in its own form class which extends FormBase. The Ajax functionality is added with the following code in buildForm() method:

$form['form_container']['actions']['submit'] = [
  '#type' => 'submit',
  '#value' => 'Submit',
  '#ajax' => [
    'callback' => '::ajaxResponse'
  ],
  '#attributes' => [
    'class' => ['js-show-throbber']
  ],
  '#weight' => -45,
];

In the form class the method is defined:

public function ajaxResponse(array $form, FormStateInterface $form_state)

When I set a breakpoint within this method for XDebug the script never stops, the process within this methods are not running.

There is no info in browser's console, it is not working in any browser and in watchdog of Drupal are no entries. For me it seems that somehow the bridge between browser / JavaScript world and the form PHP class is broken. I use the exact same PHP code for many other forms without any problem.

My question: can anybody give me a hint how exactly the bridge between browser and form class is created when the form gets rendered? How can I find out if there is a problem in the PHP form class or somewhere in JavaScript?

4
  • Can you replicate on a fresh install?
    – No Sssweat
    Commented Apr 19, 2021 at 13:06
  • Can you replicate this when logged in and/or with or without admin role? Is there any custom JS involved? BigPipe or some other caching involved?
    – leymannx
    Commented Apr 19, 2021 at 13:21
  • Thank your for your tipps... good ideas, I will check this tomorrow! Clear is: it is happening independently from the role. Cachings are deactivated. Really strange, I am very eager to find out what the problem is here... Commented Apr 19, 2021 at 14:57
  • try 'callback' => [get_class($this), 'ajaxResponse'],
    – Nikit
    Commented Apr 20, 2021 at 1:04

1 Answer 1

1

Ok, this was just a stupid mistake in a another javascript. There the jQuery method .off() was used to remove event listeners which had the effect to remove the Ajax event listener.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.