Tell us what you are trying to do?
I want to preset two custom date fields. A start and an end date.
The start and end date are prefilled by values from another post type (let's call dateMin and dateMax).
The start date should default to dateMin and the end date to dateMax.
Both date fields should be restricted to the date range (dateMin and dateMax).
If the start date is changed the lower bound of the end date should be changed accordingly.
Additionally I want to set a swiss date format.
I mostly solved it with a script.
One main problem is the loading time of the script seems sometimes to be late (windows.load event might be the wrong one).
The other one is that formatting the date format seems to break the default logic.
Is there any documentation that you are following?
https://toolset.com/forums/topic/pre-populate-cred-field-with-custom-user-meta/
https://toolset.com/forums/topic/stored-value-as-default-value-for-datepicker/
https://toolset.com/forums/topic/how-to-restrict-date-range-in-cred-date-pickers/
https://toolset.com/forums/topic/limit-date-range-for-cred-form-date-field/
Is there a similar example that we can see?
What is the link to your site?
hidden link
Additionally I want to set a swiss date format...formatting the date format seems to break the default logic.
You can modify the date format in wp-admin > Settings. The following date formats are supported by the current version of CRED:
F j, Y // December 23, 2011
Y/m/d = 2011/12/23
m/d/Y = 12/23/2011
d/m/Y = 23/22/2011
One more date format will be available when Types 2.3 is released (currently in beta):
j F Y = 08 April 2018
One main problem is the loading time of the script seems sometimes to be late (windows.load event might be the wrong one).
Usually the window load event is okay - double check there are quotes around 'window'. If that does not help you can try the generic event 'cred_form_ready', triggered on the document object:
jQuery('window').bind('load', function(){
// be sure 'window' is in quotes above
// add your code here using jQuery instead of $
});
jQuery(document).on('cred_form_ready', function(){
// add your code here using jQuery instead of $
});
Thanks for your reply. The setting of the date format in the wp settings helped.
Althought it had be nice to use the format 'd.m.Y'.
What remains:
jQuery('window').bind('load', function(){
does not work for me on chrome.
jQuery(window).bind('load', function(){
and
jQuery(document).bind('cred_form_ready', function(){
do work. But not all the time. Seems to be a timing issue. That's the first problem
The second problem comes if I set the range for a date field like
var $textfield1 = jQuery('[id^=cred_form_30_1-textfield-1]');
jQuery($textfield1).datepicker('option', {
minDate: 1524614400000,
maxDate: 1526428800000});
Then the default value disappears.
1. Can I log in and get a look at this form? I'd like to see what is happening in the browser. Private reply fields are enabled here.
2. Check the documentation for the datepicker UI widget here: http://api.jqueryui.com/datepicker/#option-maxDate
I don't think a timestamp is supported for min or max date. You must use a number of days, a JS date object, a string in your chosen date format, or a string with relative values like "+1m".
It seems like the window load event is behaving consistently for me on Chrome. Everything seems to be working well except when minDate and maxDate are set, the date format becomes incorrect. Then if I choose another date in the datepicker, the date format becomes correct again. Is that what you are seeing? Is this the only problem remaining?