Skip Navigation

[Resolved] remove date from datepicker in a cred form

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

Problem:

I have a cred form with a toolset field (type date, only date) wpcf-starting-date.

I would like to remove the possibility to select a certain date (3 January 2022).

Solution:

You can try below custom JS codes:

https://toolset.com/forums/topic/remove-date-from-datepicker-in-a-cred-form/#post-2243967

Relevant Documentation:

https://api.jqueryui.com/datepicker/

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

Our next available supporter will start replying to tickets in about 2.45 hours from now. Thank you for your understanding.

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: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by culturaI 2 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#2243595

Hello!

I have a cred form with a toolset field (type date, only date) wpcf-starting-date.

I would like to remove the possibility to select a certain date (3 January 2022).

I'm not sure about what code to insert in my form js editor.

Can i have help?

Url of the page: hidden link

Thanks

#2243967

Hello,

You can try below custom JS codes:

var unavailableDates = ["2022/1/3", "2022/1/4"]; //replace with those unavailable Dates
var datefield_slug = "insurance_expiration_date"; // replace with custom date field slug

jQuery(document).on('cred_form_ready', function(){
  var input = 'input[name="wpcf-' + datefield_slug + '[display-only]"]';
  jQuery(input).datepicker("option", "beforeShowDay", unavailable);
})

function unavailable(date) {
  var dmy = date.toLocaleDateString("zh-CN");
  if (jQuery.inArray(dmy, unavailableDates) == -1) {
    return [true, ""];
  } else {
    return [false, "", "Unavailable"];
  }
} 

More help:
hidden link

#2244053

Resolved with this adapted code:

jQuery(document).on('cred_form_ready', function(){

var input = 'input[name="wpcf-starting-date[display-only]"]';
jQuery(input).datepicker("option", "beforeShowDay", unavailable);

})

function unavailable(date) {

var date_non_disponibili = [ "20/12/2021", "27/12/2021", "3/1/2022" ]; //Date non disponibili
var data_nazione = date.toLocaleDateString("it-IT");

if (jQuery.inArray( data_nazione, date_non_disponibili) == -1) {

return [true, ""];

} else { return [false, "", "Unavailable"]; }

}

My issue is resolved now. Thank you!

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