Add custom JS

Hello there,

is there a way to add custom JS to Pro? Or do I need to add the code to my childs-theme function file?

On this site I have a form with two date-fields, using a jQuery Datepicker. How can I run my custom JS for this one? I tried with the functions-file of my child theme, but it did not worked.

Lets say I want to run this JS for my datepicker, whats the way to go?

		$('#datepicker').datepicker({
		maxViewMode: 0
	});

Thank you! :slight_smile:

Hello @xoa,

Thanks for asking. :slight_smile:

You can add custom JS code under Pro > Launch > Theme Options > JS. https://screencast.com/t/ux8qwBfdh

Thanks.

Hello,

I already checked this out before after I read a few posts here, but for me there is no JS option, just CSS. :thinking:

Hi there,

Kindly make sure that you have updated version of the theme. In case the theme is already updated, try checking for plugin conflict as there should always be the JS panel available with the custom CSS panel.

In case you are still not seeing the JS option, please provide us with the admin access to your site in a secure note.

Hello,

I solved the issue with the JS button not visible in the panel. Now I have added a bit of code

$('#vfb-field-2, #vfb-field-3, #vfb-field-203, #vfb-field-204, #vfb-field-222, #vfb-field-223').datepicker({
startDate: '+1d',
endDate: '+3y',
startView: 0  
});

The problem is it works only as long as I keep the JS panel open an click “Run”. As soon as I save it and try to see the changes without the panel , it does not work anymore.

Hi there,

How about calling it a bit late, like to make sure the fields are rendered first before calling your script?

jQuery( document ).ready( function($) {

setTimeout ( function() {


$('#vfb-field-2, #vfb-field-3, #vfb-field-203, #vfb-field-204, #vfb-field-222, #vfb-field-223').datepicker({
startDate: '+1d',
endDate: '+3y',
startView: 0  
});


}, 1000 );

} );

The 1000 is 1 second delay, you may change it depending on your preference.

Hope this helps :slight_smile:

I reduced it to 150ms which now works good. :slight_smile: Thank you!

Glad to hear it,.

Cheers!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.