Skip Navigation

[Resolved] cred module restrict date range

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

Problem:
How to restrict date picker field on CRED form with year range

Solution:
You need to add custom Javascript code to your CRED form's JS editor in order to restrict date picker field with custom year range.

You can find proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/cred-module-restrict-date-range/#post-619709

Relevant Documentation:

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

Tagged: 

This topic contains 11 replies, has 2 voices.

Last updated by culturaI 6 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#617444

Hello i would to restrict date range on cred submission (for example 1900-2000), i tried some solutions without success.

What is exact code to add to JS editor?

Thanks!

#617658

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Could you please share problem URL where you have added your CRED form and for which field you want to restrict the year range.

#618029

Hello Minesh and thanks for help,
this is the page:
hidden link

"data di nascita" is the date field interested.

#618221

Minesh
Supporter

Languages: English (English )

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

Well - When you edit your CRED form you will see the section CSS and Javascript. You should add the said code to your CRED form's Javascript section and try to resolve your issue.

jQuery(document).ready(function($) {
   jQuery( ".js-wpt-date" ).datepicker( "option", "yearRange", "2002:2012" );
});
#618433

Hello Minesh i already tried this code (i'm using on views and it's works) but on cred seem to do nothing.

Obviously i added on right CRED JS section

#618871

Minesh
Supporter

Languages: English (English )

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

*** 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 would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#619589

Minesh
Supporter

Languages: English (English )

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

Could you please check now.

I've added following code to your CRED form's JS box:

jQuery(document).ready(function($) {

date_field_id = jQuery('input[name="wpcf-data-di-nascita[display-only]"').attr('id');
 $( "#"+date_field_id ).datepicker({
    showOn: "button",
   changeMonth: true,
    changeYear: true,
     buttonImage: "<em><u>hidden link</u></em>",
   	 yearRange: "1900:2000",
     buttonImageOnly: true
    });

});

And now I can see the specified "yearRange" is set with the datepicker. Could you please confirm.
hidden link

#619691

Hello Minesh we can see specified range but now custom field don'update the value, date field remain empty.

Please you can use the form, it's only a test site

#619709

Minesh
Supporter

Languages: English (English )

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

Could you please check now:

I've added the following code to your both contact form ID 265 (Edit contact) and 36 (Create Contact).

jQuery(document).ready(function($) {

field_id_display = jQuery('input[name="wpcf-data-di-nascita[display-only]"').attr('id');
field_id_picker  = jQuery('input[name="wpcf-data-di-nascita[datepicker]"').attr('id');
    
 jQuery( "#"+field_id_display ).datepicker({
    showOn: "button",
    altFormat: '@', 
   altField: '#'+field_id_picker,
   changeMonth: true,
    changeYear: true,
     buttonImage: "<em><u>hidden link</u></em>",
   	 yearRange: "1900:2000",
     buttonImageOnly: true,
     onClose: function( selectedDate ) {
      stamp =  jQuery('#'+field_id_picker).val()/1000;
       jQuery('#'+field_id_picker).val(stamp);
       }
 
    });
   
});

And I can see now the date field is saved successfully. Could you please confirm.

#619775

yes Minesh now is working good, thanks for your work!
I would to ask you also:
it is possible to enable also write date in text format in addition to date picker?

#619777

Minesh
Supporter

Languages: English (English )

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

Glad to know that your original issue is resolved and solution I shared with you help you to resolve your issue.

May I kindly ask you to open a new ticket with your each new question. This will help other users searching on the forum. You may open a new ticket and assign it to me. Thank you for understanding.

#619779

Sure and thanks again!

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