Skip to content

Instantly share code, notes, and snippets.

@wpmudev-sls
Last active August 26, 2024 08:40
Show Gist options
  • Save wpmudev-sls/394220bc47e5a8a749f645ba6901cb0f to your computer and use it in GitHub Desktop.
Save wpmudev-sls/394220bc47e5a8a749f645ba6901cb0f to your computer and use it in GitHub Desktop.
[Forminator Pro] - Search country by first letter
<?php
/**
* Plugin Name: [Forminator Pro] Search country by first letter
* Description: Search address country by first letter match.
* Author: Prashant @ WPMUDEV
* Author URI: https://premium.wpmudev.org
* License: GPLv2 or later
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
add_action( 'wp_footer', 'wpmudev_search_first_character_select', 9999 );
function wpmudev_search_first_character_select() {
global $post;
if ( is_a( $post, 'WP_Post' ) && ! has_shortcode( $post->post_content, 'forminator_form' ) ) {
return;
}
?>
<script type="text/javascript">
jQuery(document).ready(function($){
setTimeout(function() {
$('.forminator-custom-form').trigger('after.load.forminator');
},500);
$(document).on('after.load.forminator', function(e, form_id) {
if ( 'forminator-module-2960' === e.target.id ) { // Please change 2960 to your form's ID.
$select = $('select[name="address-1-country"]'); // Please change address-1 to your address field.
$dropdownClass = 'forminator-custom-form-2960 forminator-dropdown--default'; // Please change 2960 to your form's ID.
$select.FUIselect2( {
'matcher' : matchCustom,
'dropdownCssClass': $dropdownClass,
});
function matchCustom(params, data) {
if ($.trim(params.term) === '') {
return data;
}
if (typeof data.text === 'undefined') {
return null;
}
if (data.text.toLowerCase().indexOf(params.term.toLowerCase()) === 0) {
var modifiedData = $.extend({}, data, true);
return modifiedData;
}
return null;
}
}
});
});
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment