Last active
August 26, 2024 08:40
-
-
Save wpmudev-sls/394220bc47e5a8a749f645ba6901cb0f to your computer and use it in GitHub Desktop.
[Forminator Pro] - Search country by first letter
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 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