Skip Navigation

[Resolved] Default date in datepicker

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 8 replies, has 2 voices.

Last updated by Minesh 9 months, 3 weeks ago.

Assisted by: Minesh.

Author
Posts
#2686429
date-picker-default-date.png

We inserted a custom search filter in a view. Type of control = datepicker, comparison = between. This works fine. Now we would like to start with a default min date. Therefore we inserted TODAY() in default date. Unfortunately the timetamp is inserted in both the datepicker for min and the datepicker for max. We only want to te set the Timestamp for the min datepicker. Second issue: In the frontend the timestamp is pre-selected. However, you must click Submit for this filter to be activated (or changing a filter when using ajax refresh on filter change). So we think, there should be an automatic refresh on frontend, when a default date is set. Please see my screenshot for reference. Best regards, Christian.

New threads created by Minesh and linked to this one are listed below:

https://toolset.com/forums/topic/split-default-date-in-datepicker-default-date-filter-for-custom-search/

#2686444

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

As per our support policy, we entertain only one question per ticket. This will help other users searching on the forum as well as help us to write problem resolution summery for the original issue reported.

I will address the first question here and the second issue is handle with the following split ticket:
- https://toolset.com/forums/topic/split-default-date-in-datepicker-default-date-filter-for-custom-search/

Can you please try to add the following custom JS code to your view block's custom JS sectoin:

jQuery(document).ready(function($){
$('.wpv-date-front-end-clear:eq(1)').trigger('click');
});

More info:
- https://toolset.com/course-lesson/adding-custom-javascript-to-views-templates-and-archives/#steps-for-adding-javascript-to-a-view

#2686496

Hi Minesh, cool that works! When loading the page, the view reloads automatically and only the start date is set. One last thing: When a user clicks the custom search reset button, both datepickers are pre-selected again. Please see it live here: hidden link So maybe the function could include a second trigger for the reset button? Thank you for your awesome support!!!

#2686497

Minesh
Supporter

Languages: English (English )

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

What is your custom search settings?
- Full page refresh when clicking Submit
- AJAX refresh when clicking submit
- AJAX refresh when changing any filter

Can you please confirm? I set it to "Full page refresh when clicking Submit".

#2686498

Our search setting is "AJAX refresh when changing any filter". We also tried "Full page refresh when clicking Submit" with your function. But then users have to click the submit button first.

#2686502

Minesh
Supporter

Languages: English (English )

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

You will have to compromise a bit here as you have custom requirement. You will have to use the option " Full page refresh when clicking Submit" to see it working.

#2686512

We set Full page refresh when clicking Submit. But now each time a user clicks on the search button, the second datepicker is cleared. We only want to clear the second datepicker when the view loads initially.

#2686592

Minesh
Supporter

Languages: English (English )

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

Glad to know that the solution I shared help you to resolve your issue. You're welcome to mark resolve this ticket.

#2686626

Minesh
Supporter

Languages: English (English )

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

You're welcome to mark resolve this ticket.

#2686645

Hi Minesh, we ultimately decided on a different solution. Here's what we've done: We left the default date empty AND we also did not included any jQuery to click the "wpv-date-front-end-clear". We just entered a placeholder in the menu item. With a custom php function (via filter wp_nav_menu_objects) we replace this placeholder with the standard toolset url parameter we needed. Works great. Here's the code:

function my_dynamic_menu_items( $menu_items ) {
$placeholder ='#starttoday#';
foreach ( $menu_items as $menu_item ) {
$pos = strpos($menu_item->url, $placeholder);
if ($pos !== false) {
$menu_item->url = str_replace('#starttoday#', '?wpv-blended_learning_start_date_min='.strtotime(date('Y-m-d')), $menu_item->url );
}
}
return $menu_items;
}
add_filter( 'wp_nav_menu_objects', 'my_dynamic_menu_items' );