Currently, I'm working on an events view in Drupal 8 which needs to only show events that are on or after the current date (now() filter). This view also has an exposed date range filter that allows user's to select a start date and end date. The start date can be from before the current date.

The problem is that the now() filter isn't letting user's see anything before the current date. How can I remove the now() filter when a user enters a start date so they see the list of all the events in the date range they've selected?

| improve this question | | | | |
  • I'd remove the filter and set a default value for the exposed filters instead – Hudri Apr 25 '19 at 16:12
  • Thanks for the suggestion, @Hudri Do you know of a way to programmatically remove the default value after the page loads? So the user isn't faced with an input field that reads "now"? – bcanini Apr 25 '19 at 18:37

You can do this by combining two "Authored on" Filters, one regular and the other one Exposed with the OR Operator working between them/groups of Filters.

Add the regular "Authored on" Filter Is less than or equal to now.

Add another "Authored on" Filter and Expose it with your preferred settings, how you want your visitors to use it, don't enter a default value.

Then under Add dropdown choose And/Or Rearrange, Create a new filter group. move the Exposed "Authored on" to it, and choose the OR between the groups, while keeping AND within groups.

Recreate any Filters you might need in the second group.

That's it!

Be very careful of your entire Filters configuration. If you have Exposed filters in the first group too, they will not be able to be applied at the same time (because OR), which may be confusing to users...

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.