Lookup Fields Bug?

By: Michael Clark | Asked: 06/05/2022
ForumsCategory: General questionsLookup Fields Bug?
Michael ClarkMichael Clark asked 2 years ago
Not sure if it's a bug or if I'm misunderstanding the basic functionality of the Lookup field. Problem: Accessing a form with two Lookup fields via a [frmmodal] in a View, the second Lookup field watches the first to derive its values, and only works when the modal is launched from the first record of the View. Doesn't matter if the View is paginated or not. As a matter of fact, when I paginate the View, the second Lookup works on the first record of every page in the View, but only on the first record of each page in the View. Context:
  • Form with four fields, accessed via a [frmmodal] button
    Two text fields, default values to [get param], passed in via [frm-set-get]
    Two Lookup fields, the second, watching the first
  • Form set to load with Ajax (or not)
The form's Lookups work fine when the form is embedded on a separate page. Only fails in a modal. Are Lookups intended only when the form is in a dedicated page, not in a modal?
2 Answers
Victor Font answered 2 years ago
I'm not 100% certain about this, but if frmmodal is loading through an Ajax call, it's possible the HTML Document Object Model (DOM) is not picking up the jQuery required to make the lookups work together. When using Ajax, everything has to be loaded when the page is generated. HTML locks down the DOM and in order to add new functionality, the DOM needs to reinitialized. This is a known issue with anything that generates content with Ajax. While this tutorial won't exactly help with your issue, it does explain how the DOM works with Ajax and how to reinitialize the DOM after an Ajax call. There's also a workaround available for Safari. Testing shows that Safari has an incomplete jQuery implementation compared to the other major browsers.
Michael ClarkMichael Clark replied 2 years ago

<p>Thanks, Victor. Interesting insight. Sounds legit to me. The dependent Lookup works exactly once, so it may very well be that while everything is rendered on the page, subsequent fires of the modal won't be able to re-intialize since the page is fully rendered and the DOM's locked down thereafter. Too bad the form in the modal can't maintain state.</p><p>The weird thing is the spinner indicating the dependent Lookup is adapting to the Lookup it's watching, going to fetch the related values, that happens within the first instance of the modal all day long. I can go into the form the Lookup's watching and change values and in the modal, it still goes out and gets the current dependent values. Would seem that it wouldn't do that if it was an AJAX-y gotcha. Meh. Matters not. I have to figure out a way to get related Lookups to work in a modal, somehow. xP </p><p>I may try to make them Dynamic fields and see if that has any effect. Or do an inline form in the view, maybe. I have a nice simple modal with a single pair of Lookups that simply refuses to do my bidding. Wrecks the UX, too. Makes me force the user into a flow where every time they want to take this action, they have to load an extra page for this one little form. And while technically, it'd be less than 100 times every few months, it's still a really poor experience. That's still a lot of back n forth for an otherwise very efficient and performant flow. I tried a pop-up plugin, but it ignores the url params and that doesn't do any good for the rest of the flow.</p><p> </p><p>As always, thanks for your insights!</p>

Michael ClarkMichael Clark answered 2 years ago
It's not a bug, necessarily. Formidable Support that the issue has to do with the fact that you can't embed the same form multiple times on the same page without encountering lots of errors. The modal simply wraps the form in another shortcode, so it's technically embedded in the page for however many rows are in the view. Need to find a solution because jumping back and forth between two pages hundreds of times is *really* bad UX.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right