I am adding enlace oculto using wp_enqueue_scripts and admin_enqueue_scripts, this is mostly working as expected but I am getting console errors and some pages not loading correctly.
It looks like this might be because of the lazy loading?
What is the correct way to make sure the toolset datepicker is loaded before loading the addon?
Thanks in advance.
Hello,
I assume you are going to trigger your custom JS codes after Toolset post forms are loaded.
If it is, you can try the JS event "cred_form_ready", for example:
jQuery(document).on('cred_form_ready', function(){
// setup your custom JS codes here ...
});
How would I use that with enqueue_scripts? I can use that for custom code on a page but not when loading Jquery addon scripts.
You can follow WP document to enqueue your JS files:
https://developer.wordpress.org/reference/functions/wp_enqueue_script/
And the JS event "cred_form_ready" is triggered after JS files are loaded(enqueued)
As I said in the original question, I have already used the wp_enqueue_scripts, but any scripts I enqueue are loaded before toolset scripts.
It doesn't matter when the cred_form_ready is called, if the addon script has already failed because wordpress tried to load it before a script that it depends on (toolset date picker).
As I mentioned above:
https://toolset.com/forums/topic/using-multidatepicker-jquery-addon/#post-2193857
the JS event "cred_form_ready" is triggered after JS files are loaded(enqueued)
So you can setup your custom JS codes like this:
https://toolset.com/forums/topic/using-multidatepicker-jquery-addon/#post-2193425
And you can put the custom JS codes into your toolset post form, section "JS editor"
As per the first link, it is not custom code it is a jquery plugin/addon, developed and maintained by someone else.
That is why I am using wp_enqueue_scripts to load a script file.
how do I load an external file with https://toolset.com/forums/topic/using-multidatepicker-jquery-addon/#post-2193425
There might be some misunderstandings.
1) You can follow WP document to load other custom JS files with wp_enqueue_scripts:
https://developer.wordpress.org/reference/functions/wp_enqueue_script/
2) In your post form, section "JS editor", you can setup custom JS codes, for example:
jQuery(document).on('cred_form_ready', function(){
// setup your custom JS codes here ...
});
3) In above JS codes, below this line
// setup your custom JS codes here ...
You can follow their document to setup the custom JS codes:
enlace oculto
section "Demos", you should be able to see example codes in the tab "Javascripts"
Hope it is clear
I understand that, but I do not understand how that fixes my issue.
The files are enqueued and the files are loaded, but they are loaded before the toolset scripts which is an issue, as they fail because the depend on them.
My original question is how can I make the enqueued scripts load after the toolset datepicker scripts, NOT the custom code.
I can put the custom code anywhere or not include it at all as it still wont work, if the enqueued script is not fails.
How do you enqueue the files?
What errors do you get?
Is it "Uncaught TypeError: Cannot read property 'multiDatesPicker' "?
I have tried it in my localhost with a fresh WP installation Without Toolset plugins, enqueue "Multiple-Dates-Picker-for-jQuery-UI" JS/CSS files, and get below JS error:
jquery-ui.multidatespicker.js:488 Uncaught TypeError: Cannot read properties of undefined (reading 'multiDatesPicker')
Is it the same JS errors you mentioned above?
If it is, it is a known issue of "Multiple-Dates-Picker-for-jQuery-UI", see below link:
enlace oculto
You need to contact the author of "Multiple-Dates-Picker-for-jQuery-UI" for it.