Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wpmudev-sls/104f30388b5419aab8b547db4fe08d23 to your computer and use it in GitHub Desktop.
Save wpmudev-sls/104f30388b5419aab8b547db4fe08d23 to your computer and use it in GitHub Desktop.
[Forminator Pro] - Fix select element dropdown position
<?php
/**
* Plugin Name: [Forminator Pro] Fix select2 dropdown position
* Description: Fixes select2 dropdown position.
* Author: Prashant @ WPMUDEV
* Task: SLS-7114
* Author URI: https://premium.wpmudev.org
* License: GPLv2 or later
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Fix select2 position.
*/
function wpmudev_form_selection_fix() {
global $post;
if ( is_a( $post, 'WP_Post' ) && ! has_shortcode( $post->post_content, 'forminator_form' ) ) {
return;
}
?>
<script id="wpmudev-select2-fix" type="text/javascript">
jQuery(document).ready(function($){
$(document).on('after.load.forminator', function(e, form_id) {
if ( form_id === '4754' ) { // Please change the form ID.
$('#forminator-module-'+form_id).find('select').each(function(){
$(this).on('select2:open', function() {
var select_offset = $(this).offset();
setTimeout(function(){
if ( $('#wpadminbar').length ) {
var top = +(select_offset.top) + 9;
} else {
var top = +(select_offset.top) + 42;
}
$('.forminator-select-dropdown-container--open').attr('style', "left: " + select_offset.left + "px !important; top: " + top + "px !important; position: absolute !important;");
},2);
});
});
}
});
});
</script>
<?php
}
add_action( 'wp_footer', 'wpmudev_form_selection_fix', 9999 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment