Skip Navigation

[Resuelto] Using Multidatepicker Jquery addon

This support ticket is created hace 3 años, 1 mes. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Este tema contiene 9 respuestas, tiene 2 mensajes.

Última actualización por Luo Yang hace 3 años, 1 mes.

Asistido por: Luo Yang.

Autor
Mensajes
#2192827

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.

#2193425

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 ...
});
#2193823

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.

#2193857

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)

#2194273

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).

#2194423

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"

#2194667

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

#2194669

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

#2195151

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.

#2195429

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.