Skip Navigation

[Resolved] Setting maxDate on Date field in CRED form resets default value

This support ticket is created 5 years, 2 months 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 4 replies, has 2 voices.

Last updated by davidS-53 5 years, 2 months ago.

Assisted by: Nigel.

Author
Posts
#1199089

I have a basic date field, and have made a shortcode that sets the default date to today:

[cred_field field='date-checked' value='[wpv-post-today]' urlparam='' class='form-control' output='bootstrap']

I also want to restrict the maxdate for that field to tomorrow. I found this code:

jQuery(window).bind("load", function() {
  jQuery('[id^="cred_form_302_1-textfield"]').datepicker('option',{minDate: '-5y',maxDate: 1});
});

However, the JQuery resets the value I've preset the date field with. Any ideas on a workaround? Cheers!

#1199104

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi David

You are already manipulating the datepicker options, you can additionally set the defaultDate option: hidden link

#1199646

Ah right that makes sense. That makes my code this:

jQuery(window).bind("load", function() {
  jQuery('[id^="cred_form_302_1-textfield"]').datepicker( 'option', {minDate: '-5y', maxDate: 0} );
  jQuery('[id^="cred_form_302_1-textfield"]').datepicker( 'option', 'dateFormat', 'MM d, yy' );
  jQuery('[id^="cred_form_302_1-textfield"]').datepicker( 'setDate', new Date() );
});

However I can't seem to achieve the same result for the time- it's in a select field?

#1199739

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

The time selectors are not part of the jQuery datepicker widget, they are added by the form.

What is it you are trying to do?

If you want to set a default time then you would probably need to set those chosen options using JS on dom ready, but what time do you want to set them to?

#1200274

Well when I was setting the value of the datetime field with that shortcode it set the time as well. All I want to do is set the time of that field to the current time. I should be able to sort it out from here, cheers.

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