Advertisement
adczk

Forminator - preferred country

Jul 19th, 2023
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. add_action( 'wp_footer', 'wpmudev_fix_intelinput_country', 9999 );
  2. function wpmudev_fix_intelinput_country() {
  3. global $post;
  4. if ( is_a( $post, 'WP_Post' ) && !has_shortcode($post->post_content, 'forminator_form') ) {
  5. return;
  6. }
  7. ?>
  8. <script type="text/javascript">
  9. jQuery( document ).ready( function($) {
  10. setTimeout(function() {
  11. $('.forminator-custom-form').trigger('after.load.forminator');
  12. },100);
  13.  
  14. $(document).on('after.load.forminator', function(e, form_id) {
  15. if ( e.target.id == 'forminator-module-2910' || e.target.id == 'forminator-module-3210' ) {
  16. var form = $( '#'+e.target.id ),
  17. is_material = form.is('.forminator-design--material'),
  18. fields = form.find('.forminator-field--phone');
  19. fields.each(function () {
  20. $(this).intlTelInput('destroy');
  21. var is_national_phone = $(this).data('national_mode'),
  22. country = $(this).data('country'),
  23. validation = $(this).data('validation');
  24.  
  25. if ('undefined' !== typeof (is_national_phone)) {
  26.  
  27. if (is_material) {
  28. //$(this).unwrap('.forminator-input--wrap');
  29. }
  30.  
  31. var args = {
  32. nationalMode: ('enabled' === is_national_phone) ? true : false,
  33. initialCountry: 'undefined' !== typeof ( country ) ? country : 'us',
  34. utilsScript: window.ForminatorFront.cform.intlTelInput_utils_script,
  35. };
  36.  
  37. if ( 'undefined' !== typeof ( validation ) && 'standard' === validation ) {
  38. args.allowDropdown = false;
  39. }
  40. // stop from removing country code.
  41. if ( 'undefined' !== typeof ( validation ) && 'international' === validation ) {
  42. args.autoHideDialCode = false;
  43. }
  44.  
  45. args.preferredCountries = ["al", "us", "gb"]; //These countries will appear at the top
  46.  
  47. $(this).intlTelInput(args);
  48.  
  49. if ( 'undefined' !== typeof ( validation )
  50. && 'international' === validation ) {
  51. var dial_code = $(this).intlTelInput( 'getSelectedCountryData' ).dialCode,
  52. country_code = '+' + dial_code;
  53. if ( country_code !== $(this).val() ) {
  54. var phone_value = $(this).val().trim().replace( dial_code, '' );
  55. $(this).val( country_code + phone_value );
  56. }
  57. }
  58.  
  59. if ( ! is_material ) {
  60. $(this).closest( '.forminator-field' ).find( 'div.iti' ).addClass( 'forminator-phone' );
  61. } else {
  62. $(this).closest( '.forminator-field' ).find( 'div.iti' ).addClass( 'forminator-input-with-phone' );
  63.  
  64. if ( $(this).closest( '.forminator-field' ).find( 'div.iti' ).hasClass( 'iti--allow-dropdown' ) ) {
  65. $(this).closest( '.forminator-field' ).find( '.forminator-label' ).addClass( 'iti--allow-dropdown' );
  66. }
  67. }
  68.  
  69. // intlTelInput plugin adds a markup that's not compatible with 'material' theme when 'allowDropdown' is true (default).
  70. // If we're going to allow users to disable the dropdown, this should be adjusted accordingly.
  71. if (is_material) {
  72. //$(this).closest('.intl-tel-input.allow-dropdown').addClass('forminator-phone-intl').removeClass('intl-tel-input');
  73. //$(this).wrap('<div class="forminator-input--wrap"></div>');
  74. }
  75. }
  76. });
  77. }
  78. });
  79. });
  80. </script>
  81. <?php
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement