I've created a job board that uses a (Cred) form to add a new job. The form has a date picker to set a date to set an expiration date, i.e. remove the job.
When creating a new job posting, I need to default / pre-populate the field to 60 days in the future, while retaining the ability to change it.
Hello. Thank you for contacting the Toolset support.
Do you mean that when the date field is displayed it should be by default set default date as current date + 60 days?
To override the datepicker option for your custom date field as per your requirement, I've adjusted the JS code you have added to your form's JS box as given under:
jQuery(window).load(function() {
id = jQuery('input[name="wpcf-your-field-slug[display-only]"').attr('id');
jQuery( "#"+id ).datepicker("option","setDate","+60d");
});
Where:
- Replace "your-field-slug" with your original field slug.
Yes, when the the form loads for adding a new job, I would like the date picker to default / pre-populate with the date 60 days out from today.
I added the code you shared to the JS section of the form. When I load the form, I see no change (no default remove date) and, just to check, when I try to save it I get the required-field error.
Can you please share problem URL where you added the form as well as 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 have set the next reply to private which means only you and I have access to it.
If it won't work with the date picker, can I have a text field that can have a default value and just make sure it is a valid date? I need the date picker less than I need a valid date and a default of 60 days out.
Sorry - I'm bit confused about your requirement and the following statement:
Also, please consider my other option about just using a text field that requires to validate as a date and defaults to a value of today+60 days (and not use the date picker).
=> Do you mean that you only want to display plain text field holding the date string where default date should be set as current date + 60 days? - Do you want that user should not be allowed to make any changes to the default date?
I need a date field that the user can fill in with a specific date (the remove date). However, I would like the date to automatically be filled in with a date of today+60 days. That is a relatively common remove date (these are job postings) but the user should be able to change if they want.
My other comment just meant that this date field does not necessarily need to be presented on the form as a date picker. It could be a regular text field, if that's easier to implement. But in either case, pre-filled with a date 60 days out but changeable to whatever date.
Can you please check now. I've added the following code to your form's JS box:
jQuery(document).ready(function(){
jQuery(window).bind("cred_form_ready", function() {
var currentDate = new Date();
var numberOfDaysToAdd = 60;
var millisecondOffset = numberOfDaysToAdd * 24 * 60 * 60 * 1000;
var total_time = currentDate.getTime()+millisecondOffset ;
var currentDate = new Date(total_time);
var day = currentDate.getDate().toString().padStart(2, "0");
var mon = (currentDate.getMonth()+1).toString().padStart(2, "0");
var res_date = mon+"/"+day+"/"+currentDate.getFullYear();
jQuery('input[name="wpcf-remove-date[display-only]"').attr('value',res_date);
jQuery('input[name="wpcf-remove-date[datepicker]"').attr('value',parseInt(total_time/1000));
});
});
If you can see the page now, we added 60 days to the current date. It's hard to convert to the text box so I suggest you go with the current situation:
=> hidden link
PS. Thank you for putting in the extra time. I was concerned that your available hours were up. If you seen that there was a transfer of this ticket, that's why.