Does not work with rendered view

Created on 2 April 2025, 9 days ago

Hello,

I have installed this module in a Drupal 11 installation. In this project, I need to load a view dinamycally with ajax and put inside a div.

To do this, I amb rendering the view inside a controller:

    $view = \Drupal\views\Views::getView('patient');
    if (is_object($view)) {
      $view->setDisplay('default');
      $view->preExecute();
      $view->setArguments([\Drupal::currentUser()->id(), $user->id()]);
      $view->execute();
      $view->render();
    }

    return new Response(\Drupal::service('renderer')->render($view->render()));

And then, I amb loading it with js:

$("#patient-view").load('/patient/3');

The view is rendered properly, but when I submit the form it redirects to a not found page. I have checked the generated html and I found that the form action is diferent.

By default, the form action is the same than current page but on rendering, the form action is a token:

  • default action: /patients
  • rendered action: form_action_p_pvdeGsVG5zNF_XLGPTvYSKCf43t8qZYSwcfZl2uzM

I tried modifying the action and set the default route but throws the following error:

"The form has become outdated. Press the back button, copy any unsaved work in the form, and then reload the page."

Is there a way to solve this issue?

Thanks!

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇪🇸Spain dromansab

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024