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?
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]"]
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.
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."
I will close this ticket since we have moved our conversation into a different ticket.