Skip Navigation

[Resolved] make datepicker required

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

Problem:
The user would like to make a date-picker required inside a form.

Solution:
The date picker field stores the date inside a hidden input field. You can target it using Javascript as follow:

jQuery(function($){
    $('div[data-item_name="date-wpcf-day-of-birth"] input').prop('required', true)
})
This support ticket is created 3 years, 7 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
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: Africa/Casablanca (GMT+01:00)

This topic contains 2 replies, has 2 voices.

Last updated by Puntorosso 3 years, 7 months ago.

Assisted by: Jamal.

Author
Posts
#2039135

How do I apply your Javascript solution to make the date field (day-of-birth) required?
hidden link

#2039159
#2039753

It turns out to be as simple as setting both inputs as required, the visible one is display_only, and it displays the value of the hidden one. We can target them with div[data-item_name="date-wpcf-day-of-birth"] input.


jQuery(function($){
    $('div[data-item_name="date-wpcf-day-of-birth"] input').prop('required', true)
})

Can you test it for a new order? the existing one has already the date value.

#2039907

Perfect! Thanks a lot Jamal.
Best