Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 295338

Rebuild multiple forms on a page via AJAX

$
0
0

We have a page that contains multiple forms (for filtering elements on the rest of the page).
The forms are defined with individual classes and store filtering IDs in the session.

The issue we're running into is when one filter is changed, we need to rebuild and replace some of the other forms on the page.

So, I'd like to know how to:

1: Store the form build ID in the user session or keyvalue store. (we have this partially working, but there must be a better drupaly way)
2: Load a given form and form_state from cache using the build ID
3: Rebuild and update the cached form

After the form is rebuilt, we output it back to the browser with a ReplaceCommand (working).

Currently, the ReplaceCommand stuff works if we use \Drupal::formBuilder()->getForm(...) to get a fresh form, AS LONG AS that form hadn't previously been submitted (once submitted, it has a form,form_state in the key_value_expire table). Replacing a form that has a saved state appears to break the autocompletes in the forms.

Myself and another developer have spent multiple days digging through code and docs to determine how to load a form+state from a build ID, but have run into multiple roadblocks.

Thanks for any help you can provide!


Viewing all articles
Browse latest Browse all 295338

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>