Unable to make imports to work
Hello all.
I am creating a small form based in a given json, but my dynamic imports are not working properly, it add only after the function is called causing a function to not be found.
In order to make this import I did this small function:
- function include(scriptName){
- var head = document.getElementsByTagName('head')[0];
-
- script = document.createElement('script');
- script.src = scriptName;
- script.type = 'text/javascript';
-
- head.appendChild(script);
- }
-
It works as it should, but the order is not being respected here. In my ready function I did:
- $(document).ready(function(){
- // import required scripts
- importRequirements();
-
- // 1. grab panel that will receive groups
- $checklistPanel = $("#checklist-form");
-
- // This setter will be here ONLY because the mock, must be removed once all is ok
- setCurrentCheckList("Remove after this after checklist is done");
-
- // 2. now, start creating groups
- createGroups($currentCheckList.groups, $checklistPanel);
-
- // 3. after group creation, transform it into an accordion
- $checklistPanel.accordion({
- collapsible: true
- });
- });
The import is there if I check the html in chrome console, but at the sources tab, it is added only after the exception is fired.
I tried adding it to document onload, the result was the same, it loads only after the method createGroups has been runned once.
Is there something that I can do without having to add it to the header? There are 9 scripts, and they will always be used when this script is used, that is why I am trying to add it programatically.