Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'wp_footer', 'wpmudev_fix_intelinput_country', 9999 );
- function wpmudev_fix_intelinput_country() {
- 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');
- },100);
- $(document).on('after.load.forminator', function(e, form_id) {
- if ( e.target.id == 'forminator-module-2910' || e.target.id == 'forminator-module-3210' ) {
- var form = $( '#'+e.target.id ),
- is_material = form.is('.forminator-design--material'),
- fields = form.find('.forminator-field--phone');
- fields.each(function () {
- $(this).intlTelInput('destroy');
- var is_national_phone = $(this).data('national_mode'),
- country = $(this).data('country'),
- validation = $(this).data('validation');
- if ('undefined' !== typeof (is_national_phone)) {
- if (is_material) {
- //$(this).unwrap('.forminator-input--wrap');
- }
- var args = {
- nationalMode: ('enabled' === is_national_phone) ? true : false,
- initialCountry: 'undefined' !== typeof ( country ) ? country : 'us',
- utilsScript: window.ForminatorFront.cform.intlTelInput_utils_script,
- };
- if ( 'undefined' !== typeof ( validation ) && 'standard' === validation ) {
- args.allowDropdown = false;
- }
- // stop from removing country code.
- if ( 'undefined' !== typeof ( validation ) && 'international' === validation ) {
- args.autoHideDialCode = false;
- }
- args.preferredCountries = ["al", "us", "gb"]; //These countries will appear at the top
- $(this).intlTelInput(args);
- if ( 'undefined' !== typeof ( validation )
- && 'international' === validation ) {
- var dial_code = $(this).intlTelInput( 'getSelectedCountryData' ).dialCode,
- country_code = '+' + dial_code;
- if ( country_code !== $(this).val() ) {
- var phone_value = $(this).val().trim().replace( dial_code, '' );
- $(this).val( country_code + phone_value );
- }
- }
- if ( ! is_material ) {
- $(this).closest( '.forminator-field' ).find( 'div.iti' ).addClass( 'forminator-phone' );
- } else {
- $(this).closest( '.forminator-field' ).find( 'div.iti' ).addClass( 'forminator-input-with-phone' );
- if ( $(this).closest( '.forminator-field' ).find( 'div.iti' ).hasClass( 'iti--allow-dropdown' ) ) {
- $(this).closest( '.forminator-field' ).find( '.forminator-label' ).addClass( 'iti--allow-dropdown' );
- }
- }
- // intlTelInput plugin adds a markup that's not compatible with 'material' theme when 'allowDropdown' is true (default).
- // If we're going to allow users to disable the dropdown, this should be adjusted accordingly.
- if (is_material) {
- //$(this).closest('.intl-tel-input.allow-dropdown').addClass('forminator-phone-intl').removeClass('intl-tel-input');
- //$(this).wrap('<div class="forminator-input--wrap"></div>');
- }
- }
- });
- }
- });
- });
- </script>
- <?php
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement