Skip Navigation

[Gelöst] DatePicker min max range based on selections

This support ticket is created vor 4 Jahre, 5 Monate. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 6 Antworten, has 2 Stimmen.

Last updated by Christian Cox vor 4 Jahre, 5 Monate.

Assisted by: Christian Cox.

Author
Artikel
#1386051
dates-pic.PNG

I am using this js code on my post form to manipulate the datepickers:

jQuery(document).ready(function() {
    var fromId = jQuery('input[name="wpcf-post-date[display-only]"]').attr('id');
    var toId = jQuery('input[name="wpcf-post-end-date[display-only]"]').attr('id');  
    var $from = jQuery( '#' + fromId );
    var $to = jQuery( '#' + toId );
   
    $from.datepicker('option', 'dateFormat', 'd MM yy' );
    //$from.datepicker('option', 'minDate',0);
    $from.datepicker('option', 'onSelect', function( selectedDate, obj ) {
		$to.datepicker( "option", "minDate", selectedDate );      
    });

    $to.datepicker('option', 'dateFormat', 'd MM yy' );
    $to.datepicker('option', 'onSelect', function( selectedDate, obj ) {
        $from.datepicker( "option", "maxDate", selectedDate );
    });
});

I can see the datepickers range is working based on selection but the value is not saved on the form. So when I submit the form I get error fields are required (because the value is not set).

I see there are many references on the forum but can't make that work. Thanks

#1386123

Hello, this is a tricky issue because there is no consistent "form ready" event hook for JavaScript initialization. The jQuery document ready event is too soon, because Forms does other manipulation to the datepicker after document ready. So any initialization you do on document ready is prone to be overwritten. Instead, you can try wrapping your code in a short timeout, but you should be aware that this is a hack and it's not 100% guaranteed to work. Unfortunately until our developers add a consistent event hook for the form ready event, this is the best solution available.

jQuery(document).ready(function() {
    setTimeout(function() {
        var fromId = jQuery('input[name="wpcf-post-date[display-only]"]').attr('id');
        // ... your code continues here
    }, 500 );
});

If this update doesn't resolve the problem, I'll need to see the Form on the front-end of your site to make other recommendations.

#1386149
data-ajax.PNG

Hi, thanks for your prompt reply. I already saw that on other tickets, tried it but with no luck.
Notice that the js code is working as expected. I can see that when this js code is in place the ajax request in the picture above is not fired. Please mark the next reply as private so I can provide you the credentials. thanks

#1386163

Private reply fields are enabled.

#1387153

Okay I took a look at your site and code, and I don't see that you're doing anything wrong. This just isn't working, because Forms internal JavaScript is not designed to support changing datepicker options in the onSelect or onClose event handlers at this time. There are multiple inputs in play for each datepicker you see on the front-end with various event handlers, and the custom JavaScript shown in your example doesn't update the datepicker fields as needed behind the scenes when the options are modified.

Our lead developer has informed us that since the initialization event hook isn't reliable yet, there is no good solution here short of a fully custom datepicker implementation. As it turns out, we are unable to document or provide any working solutions to this problem right now, because of the unreliable event limitation. If you'd like to see more reliable ways to manipulate the built-in Forms datepicker options based on input events from other datepickers, I encourage you to submit your request in our feature request form here: https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

This will let our management know you want this feature addressed in a future release of Forms.

#1388597

Thanks for your time, I will create a feature request as I believe that this is a big gap on forms.

#1388805

Thank you for your input, I hope to see this feature added very soon because I agree it's important for User experience.

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