Skip Navigation

[Resolved] Presetting date/time field results in weird behaviour pt. 2

This thread is resolved. Here is a description of the problem and solution.

Problem:
Presetting date/time field results in weird behaviour pt. 2

Solution:
You should try to use the "cred_form_ready" javascript method to override the date field settings.

You can find the proposed solution, in this case with the following reply:
https://toolset.com/forums/topic/presetting-date-time-field-results-in-weird-behaviour-pt-2/#post-1213485

Relevant Documentation:

This support ticket is created 5 years, 1 month ago. 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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 6 replies, has 2 voices.

Last updated by davidS-53 5 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#1209905

This is a follow-up to https://toolset.com/forums/topic/presetting-date-time-field-results-in-weird-behaviour/ since that has expired.

I've just noticed that when I submit the form with the date/time set automatically, nothing is saved to the wpcf-date-checked field.

If I manually set the date/time, it saves just fine.

Any ideas why that may be? Seems weird that it displays fine but nothing saves.

#1210372

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - when you say automatically, can you please tell me how you are passing the value to date field?

#1210390

Hi Minesh,

Code is discussed in the linked thread- I'll paste it again here:

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

		var dt = new Date();
		
		setTimeout(function() {
			$('input[name="wpcf-date-checked[display-only]"]').datepicker("option", "minDate", "-5Y");
			$('input[name="wpcf-date-checked[display-only]"]').datepicker("option", "maxDate", "0" );
			$('input[name="wpcf-date-checked[display-only]"]').val($.datepicker.formatDate('MM dd, yy', new Date()));

		}, 500 );
		
		var hour = dt.getHours();
		var minute = dt.getMinutes();

		$('select[name="wpcf-date-checked[hour]"]').val(hour);
		$('select[name="wpcf-date-checked[minute]"]').val(minute);

	});

Cheers!

#1210394

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

What if you try to use the following code:

jQuery(window).bind("cred_form_ready", function() {
 var dt = new Date();
     
    setTimeout(function() {
        jQuery('input[name="wpcf-date-checked[display-only]"]').datepicker("option", "minDate", "-5Y");
        jQuery('input[name="wpcf-date-checked[display-only]"]').datepicker("option", "maxDate", "0" );
        jQuery('input[name="wpcf-date-checked[display-only]"]').val(jQuery.datepicker.formatDate('MM dd, yy', new Date()));
 
    }, 500 );
     
    var hour = dt.getHours();
    var minute = dt.getMinutes();
 
    $('select[name="wpcf-date-checked[hour]"]').val(hour);
    $('select[name="wpcf-date-checked[minute]"]').val(minute);
 
});
#1210404

No, still isn't working sorry.

#1210423

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can I have problem URL and access details?

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#1213485

Hmm, I ended up using a mix of my original and the suggested JQuery. I set the date portion of the field with the shortcode, and the time using JQuery, and it all appears to save.

	jQuery(window).bind("cred_form_ready", function() {
		
	    var dt = new Date();
		      	      
	    var hour = dt.getHours();
	    var minute = dt.getMinutes();
	  
	    $('select[name="wpcf-date-checked[hour]"]').val(hour);
	    $('select[name="wpcf-date-checked[minute]"]').val(minute);
	  
	});

A little bit hacky but works fine.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.