Skip Navigation

[Resolved] Auto fill today date as default date

This thread is resolved. Here is a description of the problem and solution.

Problem:

How to auto fill the datepicker of post form with today?

Solution:

It needs custom codes, for example:

https://toolset.com/forums/topic/auto-fill-today-date-as-default-date/#post-2226599

Relevant Documentation:

This support ticket is created 3 years, 3 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by kelvinL-2 3 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#2226119

Dear Sir/Madam,

I have a form with a date field

        <div class="col-md-6">
          <label for="%%FORM_ID%%_invoice-date">[cred_i18n name='invoice-date-label']Invoice Date[/cred_i18n]</label>
          [cred_field field='invoice-date' force_type='field' class='form-control' output='bootstrap']
        </div>

I refer to article https://toolset.com/forums/topic/how-can-i-set-the-default-time-value-of-a-date-time-field-in-cred-form/, I can able to auto fill the time but no idea how to auto fill the date, could you help?

const d = new Date();
let hour = d.getHours();
let minute = d.getMinutes();
let todaydate = d.getDate();

jQuery( document ).ready(function($) {
 $('select[name="wpcf-invoice-date[hour]"]').val(hour);
 $('select[name="wpcf-invoice-date[minute]"]').val(minute);
});

Best regards,

Kelvin.

#2226599

Hello,

For the datepicker of Toolset Forms, you can try these:

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

More help:
hidden link

#2231419

My issue is resolved now. Thank you!