Skip Navigation

[Resolved] Having multiple instances date field pre-populate with todays' date

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

Problem:
How to pre populate date/datepicker field with current/today's date value

Solution:
You can use jQuery to set today's date for datepicker

You can find proposed solution with the following reply:
https://toolset.com/forums/topic/having-multiple-instances-date-field-pre-populate-with-todays-date/#post-406730

Relevant Documentation:
http://stackoverflow.com/questions/14580749/jquery-datepicker-set-default-date

This support ticket is created 7 years, 10 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.

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
- 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)

Tagged: 

This topic contains 12 replies, has 2 voices.

Last updated by Timothy 7 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#406356

Hi,

I need a Date field with multiple instances to automatically populate the Add Another field with the current date/time when the form is submitted. So basically, instead of the user needing to click Add Another and enter todays’ date/time this automatically occurs(a new instance is created) every time the Submit button is clicked. I think it should be possible. I know how to get todays date/time and have it auto-populate the original date field. So I think I just need the Add Another field to automatically open and have today's date also auto-populate that field.

Any way to do this?

Tim

#406496

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

As I assume you have repeating/multiple instance date field using types. Now, you want to have the second instance prepopulated with current date/time without clicking on the "add" new button which will create another instance of the field.

You may try to use some jQuery code and trigger click event of the add new button.
=> hidden link

#406532

Thanks, tried using jquery trigger but no luck yet: This is the code I see for that Add Another button for this multiple instances date field:

<input type="button" class="js-wpt-repadd wpt-repadd" data-wpt-type="date" data-wpt-id="cred_form_375_1_wpcf-date-of-cycle-completions" value="Add new Date of Cycle Completions">

And this is the jquery I added to the JS Editor:

jQuery("document").ready(function(){
  jquery("3cred_form_375_1_wpcf-date-of-cycle-completions").trigger("click");
});

This should work right?

Tim

#406534

Actually I got the trigger event to work using this:

jQuery("document").ready(function(){
  jQuery("input.js-wpt-repadd.wpt-repadd").trigger("click");
});

So now all I need is for that to be auto-populated with today's date! I have the first date field in the instance auto-populating using this in my cred form:

[php]
cred_field field='last-done' post='project' value='' urlparam='' style="display: inline;" format="m/d/Y" value="[wpv-post-today]"]
</cod>

With that shortcode [wpv-post-today] defined in my functions file. But how can I get this to also auto-populate each new instance?

Tim

#406535

Minesh
Supporter

Languages: English (English )

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

Could you please try following code:

jQuery("document").ready(function(){
  jQuery(".wpt-repadd").trigger("click");
});
#406559

Thanks, that also works to auto-open the Add Another field. I'm just trying to figure out now how to auto-populate it with todays date as I have done with the first instance of this field.

#406570

Minesh
Supporter

Languages: English (English )

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

You can use 'setDate' and target your newly created instance.

For example:

jQuery( ".selector" ).datepicker( "setDate", new Date());

More info:
http://stackoverflow.com/questions/14580749/jquery-datepicker-set-default-date

#406618

So it would be this?

jQuery(".wpt-repadd").datepicker('setDate', new Date());

That doesn't seem to work, no date is entered in the new field.

Tim

#406648

Minesh
Supporter

Languages: English (English )

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

I need to check on your install what I can do that.

Could you please share problem URL?

*** 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 would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

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

#406730

Minesh
Supporter

Languages: English (English )

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

I've added following jQuery code to your view's JS box and now you can see the default date is set for second date instence as well:

jQuery("document").ready(function(){
  jQuery(".wpt-repadd").trigger("click");
   jQuery(".hasDatepicker").datepicker("option", "dateFormat","MM d,yy").datepicker("setDate", new Date()); 
 
});

I hope above solution will help you to resolve your issue.

#406736

Thanks. It's so close. The only issue is that when I click the submit button (Done) it's not saving that new instance. I added a few on the back-end so the field is working but for some strange reason this Edit form isn't allowing that newly opened date field to be saved.

#406743

Minesh
Supporter

Languages: English (English )

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

As your original issue is resolved.

Could you please open a new ticket for your each new question. This will help other users searching on the forum.

Thank you for understanding.

#406979

Sure thing, thanks for the assistance.

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