last day (15 days later) » 

05:45
0
A: Unable to initialize external jQuery in Magento2

magefmsYou have not defined jQuery in the event function, you just need to add it like this: require([ 'jquery', 'intlTelInput', ], function($, jQuery) { console.log('sample function 1234567'); $(window).load(function() { jQuery("#country_code").intlTelInput({ ...

No luck, when I use this it shows, jQuery is not a function
try redeploy static view files
yes, I've run deploy comment as well. Thats why it ready the latest change right?
well if that doesn't work try using $ only
$("#country_code").intlTelInput
Does it mean that neither jquery or intelTelinout jqueries intialized in my page?
yes, any other clue?
05:47
regarding the first error you mentioned in your post it means that jQuery is not initialized in your jquery event function.
in my answer I indicate how to initialize it
now the new error is jQuery is not a function
right?
yes, I used function($, jQuery) and rest are same.
and the error is the same also?
on this occasion, it shows the error as jQuery is not a function.
than I tried function($, jQuery, intelTelInput) I got the same erro
jQuery.fn.intlTelInput change to jquery.fn.inTelInput
then check
if works or not
Sure, hold on for a min. I am struggling with this issue for more than one and a half day
oops. no luck
05:57
same error?
yes :-(
wait Im sorry for a bit slow reply im on mobile
i will try to modify your code
Sure, take your time
I'm thankful for your help
kindly check update answer
give me a moment
Its strange. i am getting an error as 'TypeError: g is undefined'
06:16
hmmm
wait
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"]
//onlyCountries: ["ae","bh","kw","om","qa","sa"],
});
});
});
try that one
i'm completely lost :-(
06:35
exports: 'jquery.fn.intlTelInput', caused this g undefined error, Once I replaced this back to jQuery that error has gone
07:08
and still the same error comes ?
with the code above?
07:22
yes.
07:57
butterfly
I have question
what is the name of your js file
is it intlTelInput
intlTelInput.js
or utilsIntel.js
08:17
intlTelInput.js
is it visible in the source as well?
yes, obviously. I have found something interesting
yeah what is it?
I have owlcarousel jquery function working fine in my theme, and I changed my code as below,
<script type="text/javascript">
require(['jquery', 'owlcarousel', 'intlTelInput'], function(){
jQuery(function(jQuery) {

var test = jQuery('#country_code');
console.log('sample')
test.owlCarousel({
});
});
});
</script>
It is surprisingly working fine
Great!
08:27
but if I use intlTelInput it shows test.intlTelInput is not a function
maybe naming conflict
can you try this , change path name to
paths: {
'intl': 'Ucs_Reson8/js/intlTelInput',
},
and call it like
require([
'jquery',
'intl',
],
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"]
//onlyCountries: ["ae","bh","kw","om","qa","sa"],
});
});
});
should I place inTelInput inside js/jquery/intlTelInput.js
yeah
basically
currently it is like js/intlTelInput.js
is it not there? I mean currently where did you put it?
08:30
web/js/inTelInput.js
wait
yeah it is okay
web/js/inTelInput.js → is okay
I have another solution
try inserting directly in your head
please tell me
I mean in your web head tag
but before please try this first
in your requirejs-config
use map instead

var config = {

map: {
'*': {
'intlTelInput': 'Ucs_Reson8/js/intlTelInput'
}
},
"shim": {
"intlTelInput": ['jquery'],
}
};
then in your js
require([
'jquery',
'intlTelInput',
],
function($, jQuery) {

"use strict";
$(document).ready(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"],
});
});
});
});
it should work now
following above
sure, let me try
08:57
it may hurt you, But what I've gotten is jQuery(...).intlTelInput is not a function
hmm
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"]
});
});
});
here's another solution
Create default.xml file inside app/code/Vendor/Module/view/frontend/layout/default.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/11.0.9/js/intlTelInput.min.js" src_type="url" />
</head>
</page>
<script type="text/javascript">
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"]
});
});
});
</script>
run upgrade
redeploy static content -f
then clean cache
and check if it works
ok, let me try
09:31
Same error. I dont know where am I going wrong.
it is working fine with owlcarousel
Only when I use intelInput it is throwing error
 
1 hour later…
10:38
Issue has been resolved.
I'm such a stupid.
11:04
Thanks for your patience and support. Have a good day
what was the main issue?
11:39
intelInput js version wich i used doesn't compatible with jQuery version
intelInput js version was 1.15, soreplaced with version 1.9 resolved the issue

last day (15 days later) »