Skip Navigation

[Resolved] Set "today" as default for a datepicker

This support ticket is created 5 years, 11 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by Christian Cox 5 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#1160654
Date not saved.png
datepicker.png

Hi,

I have a relationship (many to many) between two CPTs. This relationship have 2 fields: a checkbox and a date. I am using a relationship form to edit both fields. In this form, I'm using Jquery to set automatically today's date in the datepicker. The code I wrote is:

$('input[name="wpcf[fecha-de-aceptacion][display-only]"]').datepicker().datepicker('setDate', 'today');

It works. However, the date is not saved. My date field is empty despite sending the form properly (see attached images). The checkbox is saved correctly.

is my code creating an incompatibility, or something like this, with the date field?

#1160852

Unfortunately there is no JavaScript API for Forms, so the only way I can recommend to set a default date is in the Form editor in wp-admin. Use the "value" attribute to set a date using a Unix timestamp. I have a custom shortcode that will return the current timestamp:

add_shortcode( 'format-date', 'format_date_func');
function format_date_func($atts) {
  $a = shortcode_atts( array(
    'format' => 'U',
    'timestamp' => date('U'),
  ), $atts );

  $date = date($a['format'], $a['timestamp']);
  return $date;
}

Then use it in your cred_field shortcode like this:

[cred_field field="birthdate" force_type="field" class="form-control" output="bootstrap" value="[format-date]"]
#1161417

Hi,

does a cred-relationship-field shortcode accept the value attribute? I registered your shortcode and i used it in my form like this:

[cred-relationship-field name="fecha-de-aceptacion" value="[format-date]"]

Unfortunately, the output seems to be "broken". See attached image.

#1161688

Hi,

I submitted a replay some hours ago, but an error ocurred. I'll wrote the replay again to be sure you can read it. Sorry if you see it duplicated.

"Hi,

does a cred-relationship-field shortcode accept the value attribute? I registered your shortcode and I used it in my form like this:

[cred-relationship-field name="fecha-de-aceptacion" value="[format-date]"]

Unfortunately, the output seems to be "broken". See attached image."

#1163979

I will close this ticket since we have moved our conversation into a different ticket.