-
-
Save patrickfreitasdev/3795a052170b0d81662d93cee4713e6c to your computer and use it in GitHub Desktop.
[Forminator] Fix Search Inputs on Selec Fields - Ajax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: [Forminator] Fix Search Inputs on Selec Fields - Ajax Load Support | |
* Plugin URI: https://premium.wpmudev.org | |
* Description: When you add a select field on the form and also add an address field with country enabled, the placeholder for all search fields (inside the dropdown options of each one) became the same. And even that you disable the search option in the select field, the search input will be displayed - this plugin fixes these problems. | |
* Author: Glauber Silva @ WPMUDEV | |
* Author URI: https://premium.wpmudev.org | |
* Jira Task: SLS-2407 | |
* License: GPLv2 or later | |
* | |
* @package WPMUDEV_Forminator_Fix_Search_Inputs_on_Selec_Fields | |
*/ | |
defined( 'ABSPATH' ) || exit; | |
function wpmudev_forminator_fix_search_inputs_on_selec_fields() { | |
ob_start(); | |
?> | |
<script type="text/javascript"> | |
( ( $,d ) => { | |
$( d ).ready( function() { | |
$(document).on("after.load.forminator", function (e, id) { | |
$('select').on("select2:open", function (e) { | |
var placeholder = ''; | |
if ( !! this.dataset.defaultValue ) { | |
placeholder = this.dataset.defaultValue; | |
} else if ( !! this.dataset.placeholder ) { | |
placeholder = this.dataset.placeholder; | |
} | |
$('.select2-search__field').attr( "placeholder", placeholder ); | |
if ( this.dataset.search == "true" ) { | |
$('.select2-search__field').show(); | |
} else { | |
$('.select2-search__field').hide(); | |
} | |
//console.log( 'Placeholder: ', placeholder ) ; | |
//console.log("select2:open", e); | |
}); | |
}); | |
} ); | |
} ) ( jQuery,document ); | |
</script> | |
<?php | |
$javascript = ob_get_clean(); | |
echo $javascript; // phpcs:ignore | |
} | |
add_filter( 'wp_footer', 'wpmudev_forminator_fix_search_inputs_on_selec_fields', PHP_INT_MAX ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment