Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. AWS
  3. Question
AWS

intl-tel-input javascript library in Aura Component

Asked by Ankit Chauhan Jul 12, 2021 1.7K views 1 answer
Share

About this question

So I have a requirement in Aura Component were in, I need to create an international telephone input field. I found this library called https://github.com/jackocnr/intl-tel-input but I'm having issues trying to implement it. One of the requirements to implement this field is to load the javascript file utils.js for me to call validation/formatting methods already available in the library.

What i'm doing so far is present in the code below

Component :


Controller after script is loaded method :
$A.createComponent( "ltng:require", { "scripts": $A.get('$Resource.int_tel_input') + '/js/utils.js', "afterScriptsLoaded" : component.getReference('c.submit') }, function(newRequire,status, errorMessage){ if (status === "SUCCESS") { console.log('Success - > '); var body = component.get("v.body"); body.push(newRequire); component.set("v.body", body); console.log(component.get('v.body')); } } );
javascript function from library that is throwing an error.
var injectScript = function injectScript(path, handleSuccess, handleFailure) { // inject a newscript element into the page var script = document.createElement("script"); script.onload = function() { forEachInstance("handleUtils"); if (handleSuccess) handleSuccess(); }; script.onerror = function() { forEachInstance("rejectUtilsScriptPromise"); if (handleFailure) handleFailure(); }; script.className = "iti-load-utils"; script.async = true; script.src = path; document.body.appendChild(script); };
AfterScriptsLoaded is not being called so I'm sure there's something wrong with the way I try to load the javascript library.
Any tip is appreaciated or can someone point me in the right direction who have implemented this library before in Aura Component. How to create intltelinput ?

Regards

Your answer

1 Answer

More AWS discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest AWS Blogs

Guides, tips and career advice on AWS from JanBask experts.