I am using intl-tel-input plugin in a Symfony project. We currently combine Assets in order to load all js script files into one.
However the intl-tel-input plugin requires utils.js in order to enable formatting/validation etc. and it needs to be included inside the script, like this:
utilsScript: "/Resources/js/vendors/utils.js"
However if I use that I get a 404 error (file utils.js not found).
How can I load that file on the script?
This is my complete script:
$(".js-phone").intlTelInput({
autoFormat: false,
autoHideDialCode: false,
autoPlaceholder: true,
defaultCountry: "auto",
geoIpLookup: function(callback) {
$.get('http://ipinfo.io', function() {}, "jsonp").always(function(resp) {
var countryCode = (resp && resp.country) ? resp.country : "";
callback(countryCode);
});2
},
nationalMode: false,
utilsScript: "{{ include('/Resources/js/vendors/utils.js') }}" // utils.js enables formatting/validation etc.
});
According to documentation you provided utilsScript
requires path to js
file. You can't just use /Resources/js/vendors/utils.js
since Resources
is not a public directory.
Twig's include
is meant to INCLUDE file contents, so what you need to use is asset
function:
$(".js-phone").intlTelInput({
(..)
utilsScript: "{{ asset('bundles/yourbundle/js/vendors/utils.js') }}"
});