Skip Navigation

[Resolved] set datepicker to default to today

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 1 voice.

Last updated by Minesh 4 months, 1 week ago.

Assisted by: Minesh.

Author
Posts
#2800290

Tell us what you are trying to do?
I have a form with a datepicker field

<div class="form-group">
<label for="%%FORM_ID%%_job-posted-date">[cred_i18n name='job-posted-date-label']Date to job posted[/cred_i18n]</label>
[cred_field field='job-posted-date' force_type='field' class='form-control' output='bootstrap']
</div>

I want to date to default to the current date.

Is there any documentation that you are following?

I tried looking at his. https://toolset.com/forums/topic/auto-fill-today-date-as-default-date/

But couldn't get it to work.

Is there a similar example that we can see?

What is the link to your site?

This is a private form.
hidden link

#2800295

Just to clarify, I want to default the current day in the date window, not the datepicker dropdown.

#2800364

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Its not clear what exactly you want. Can I have few screenshot that should help me to understand what exactly you want.

As I understand - when the form is loaded first time with the field "Date of Job posting", you want to display current date "March 12, 2025" by default - is that correct or you want something else?

#2800404
SCR-20250312-hzcm.png

I have a form with a datepicker field. I want the current date to populate into the field by default.

#2800439

Minesh
Supporter

Languages: English (English )

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

Can you please try to add the following code to your form's JS box:

Edit your form in backend and try to add the following code to JS editor and save your form. Please delete the cache and check if this help you to resolve your issue.

jQuery(window).bind("cred_form_ready", function() {
   jQuery( 'input[name="wpcf-job-posted-date[display-only]"]' ).val(new Date());
   jQuery( 'input[name="wpcf-job-posted-date[datepicker]"]' ).val(Math.floor(Date.now() / 1000));
});
#2800457

The code provided populated into the field as this " Wed Mar 12 2025 12:42:39 GMT-0400 (Eastern Daylight Time)"
but since i needed it should be like this... "March 12, 2025". I modified the code a bit ad it works now.

Thanks

jQuery(window).bind("cred_form_ready", function() {
var now = new Date();
var options = { month: 'long', day: 'numeric', year: 'numeric' };
var formattedDate = now.toLocaleDateString('en-US', options);

jQuery('input[name="wpcf-job-posted-date[display-only]"]').val(formattedDate);
jQuery('input[name="wpcf-job-posted-date[datepicker]"]').val(Math.floor(Date.now() / 1000));
});

#2800547

Minesh
Supporter

Languages: English (English )

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

Glad to know that the issue is fixed now. You're welcome to mark resolve this ticket.