Skip Navigation

[Résolu] Auto fill today date as default date

Ce fil est résolu. Voici une description du problème et la solution proposée.

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 Il y a 2 années et 4 mois. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 réponses, has 2 voix.

Last updated by kelvinL-2 Il y a 2 années et 4 mois.

Assisted by: Luo Yang.

Auteur
Publications
#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!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.