1

I would like to initialize intlTelInput for the country code column. I have done below,

in requirejs.config.js added below

var config = {
    deps: [
    "Ucs_Reson8/js/countryCode"
  ],
  paths: {
    'intlTelInput': 'Ucs_Reson8/js/intlTelInput',
  },
  shim: {
    'intlTelInput': {
      deps: ['jquery'],
      exports: 'jQuery.fn.intlTelInput',
    }
  }

};

Then in countryCode.js added below,

require([
'jquery',
'intlTelInput',
],
function($) {
        console.log('sample function 1234567');
        $(window).load(function() {
            jQuery("#country_code").intlTelInput({
                initialCountry: "ae",
                separateDialCode: true,
                preferredCountries: ["ae","bh","kw","om","qa","sa"],
                //onlyCountries: ["ae","bh","kw","om","qa","sa"],

            });
    });
    });

But I am getting the error as below in the browser console.

TypeError: jQuery(...).intlTelInput is not a function

But in the page source I can see the utilsIntel.js

NOTE: Before trying any other solution, it would be better to check jquery and plugin version compatibility

1

You have not defined jQuery in the event function, you just need to add it like this:

require([
'jquery',
'intlTelInput'
],
function($, jQuery) {

 "use strict";
 $(document).ready(function () { 
        console.log('sample function 1234567');
            jQuery("#country_code").intlTelInput({
                initialCountry: "ae",
                separateDialCode: true,
                preferredCountries: ["ae","bh","kw","om","qa","sa"]
       });
    });
});
  • No luck, when I use this it shows, jQuery is not a function – Butterfly Apr 20 '19 at 5:01
  • try redeploy static view files – fmsthird Apr 20 '19 at 5:02
  • yes, I've run deploy comment as well. Thats why it ready the latest change right? – Butterfly Apr 20 '19 at 5:03
  • well if that doesn't work try using $ only – fmsthird Apr 20 '19 at 5:04
  • $("#country_code").intlTelInput – fmsthird Apr 20 '19 at 5:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.