Skip Navigation

[Resolved] How set the content of a date field in a toolset form by jquery .val()?

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

This topic contains 11 replies, has 2 voices.

Last updated by Minesh 10 months ago.

Assisted by: Minesh.

Author
Posts
#2678373

a.R

We address it by its name, as the id varies, the value is displayed after allowing writing to that field, but we just cannot set that value and save it with the post.

#2678415

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Can you please share more details that what value you want to set and for what field using what code?

Please share problem URL where I can see the form as well as admin access details.

*** 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 have set the next reply to private which means only you and I have access to it.

#2678435

a.R

Maybe the question is quite simple: How fill a date field in a toolset form by jquery?

#2678442

Minesh
Supporter

Languages: English (English )

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

You will have set two values one is display value and one is the value that is Unix timestamp:

For example - You should try to add the following code to your form's JS editor:

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

Where:
- change "birthdate" with above code with your original field slug.

Please check the following related ticket that might help you:
- https://toolset.com/forums/topic/in-form-default-a-date-picker-to-today-60-days/#post-1296291

#2678639

a.R

Hi Minesh 🙂

Can´t you please just tell, what to put into those date inputs and in which format?

I just want to know, what TOOLSET wants to have there.

#2678644

Minesh
Supporter

Languages: English (English )

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

Toolset datepicker you will have to change two things:
- The display value: so add the date string in your format - just like the readable date you will see once you chose the date using Toolset date picker:

 jQuery( 'input[name="wpcf-birthdate[display-only]"]' ).val('your-date-string');    

However the above is for view purpose - the above value is not get saved to database.

Toolset stores Unix Timestamp value for the date field.

 jQuery( 'input[name="wpcf-birthdate[datepicker]"]' ).val('add-unix-timestamp-value-without-quotes');
#2678659

a.R

Thank you.
Does your-date-string have to be formatted in a special way?

And how also save the time, not just the date?

#2678710

Minesh
Supporter

Languages: English (English )

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

Does your-date-string have to be formatted in a special way?
==>
The date string should be set in format equal to your date picker format.

And how also save the time, not just the date?
===>
You shared first that you want to use custom JS not save in backend. As shared before custom date field created using Types stores the Unix Timestamp value in database in postmeta table where the key would be your custom date field wpcf-custom-field-slug and value should be Unix Timestamp.

#2678788

a.R

Ok, thank you.
The problem is, the form refuses to save if we haven´t that combination of date picker and 2 select-option things(?) filled right, so if we wanna make sure that user gives us a date, and we want the form to look good, we have to fill it with the right formats, right?
Otherwise we would have to give up that check.

Or am I wrong here?

#2678887

Minesh
Supporter

Languages: English (English )

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

I'm not sure what you are talking here and what 2 select options.

Until and unless I can not see what you have on your webpage and what you want to have I can not answer much here.

If you can share problem URL and admin access details and tell me what is your expected results with what form once I review that information I will be able to guide you in the right direction.

*** 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 have set the next reply to private which means only you and I have access to it.

#2679016

a.R

The INPUT element for date+time consists of
- a date picker, that we can fill successfully now.
- two selects, one for the hour and the other one for the minute. Can you just give me a hint how to select the options here? Simple click() on them does not really work.

#2679113

Minesh
Supporter

Languages: English (English )

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

You can search for how you can set default option for select box. You can target the required element you want to set default option for.

More info:
- https://stackoverflow.com/questions/4781420/set-the-default-value-in-dropdownlist-using-jquery