Skip Navigation

[Resolved] In Form, default a date picker to today +60 days

This support ticket is created 5 years, 4 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
- 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 10 replies, has 2 voices.

Last updated by peterI 5 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#1294237
jobsdate.jpg

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.

Possible? Your help is appreciated.

#1294417

Minesh
Supporter

Languages: English (English )

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

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.

#1294979
job-board-remove-date.jpg
job-board-result.jpg
job-board-form.jpg

Hello.

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.

Suggestions?

Thanks.

#1294999

Minesh
Supporter

Languages: English (English )

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

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.

#1295275

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.

#1295669

Minesh
Supporter

Languages: English (English )

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

Thank you for sharing access details but when I login I only able to access the user profile.

Can you please give me full admin rights to that I can able to access the Toolset Form you created in the backend.

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

#1296149

Minesh
Supporter

Languages: English (English )

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

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?

#1296163

Glad you're there.

Check message #1295275

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.

I hope that clarifies.

#1296291

Minesh
Supporter

Languages: English (English )

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

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

#1296355

Fantastic!

(At least so far 🙂

I really appreciate it.

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.

#1296357

My issue is resolved now. Thank you!