Hi,
I managed to make it work.
With the provided code snippet, the scelect2 dropdown was correctly moved in the div I chose, but the scroll computation was still on, so the dropdown was moving based on scroll, when it should not move anymore (because placed in the flow of the page, so no need to manage scroll sync).
I noticed that adding the “position: relative” CSS to the containing form (#forminator-module-*id*) seems to disable the scroll computation (which was my goal), not sure why, maybe this is a condition in your plugin JS checking for parent positionning ?
With the containing form positionned as “relative”, the dropdown is correctly positionned, without trying to compute its distance from top, so it follows the page flow, it’s not bothered by any fake scroll lib anymore ??
setTimeout(function() {
jQuery('.forminator-custom-form').trigger('after.load.forminator');
},500);
jQuery(document).on('after.load.forminator', function( e, form_id ) {
const formID = e.target.id;
jQuery('#select-1 select').FUIselect2( { 'dropdownParent': jQuery(
#${formID}
) } );
});
You’ll notice that I retrieved the form ID from the event too, that way I can move the dropdown directly in the form “owning” it, that way I think it should work with multiple forms on a same page, but I didn’t try. Putting the code here if it can be of any help for other people.
And you’re right, I had to make some styling on the dropdown, some things were gone, like paddings, or the search field being hidden.
As I said I think it would be nice to consider adding a filter, or even an option in the plugin to choose between “Place dropdown in body” and “Place dropdown in form”, something like this ??
Can I ask why this choice to place the dropdown directly in the body, and move it on scroll, instead of placing it in the form directly so it doesn’t have to be moved with JS ?