Skip Navigation

[Resolved] Require at least one option in a search to be used

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

Problem:
How can I ensure to require at least one option to be selected in a Custom Filter Search on the Front End?

Solution:
What you can do, is use Custom JS for example and show the entire results only if the user actually checked at least one box.
It's not possible within Toolset using native functions.

Relevant Documentation:
https://stackoverflow.com/questions/901712/how-to-check-whether-a-checkbox-is-checked-in-jquery

This support ticket is created 6 years, 11 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 1 reply, has 2 voices.

Last updated by Beda 6 years, 11 months ago.

Assisted by: Beda.

Author
Posts
#614755

Tell us what you are trying to do?

We want to force the user to select both states and category then they can perform the search. if not display error message eg. please select a state or a category.

Is there any documentation that you are following?

I could not find any documentation about this, i am trying to do the validation using jquery on click but it does not work correctly, any suggestion would be amazing.

Is there a similar example that we can see?

It is pretty straightforward

What is the link to your site?
hidden link It is the site mentioned above.

Thanks!

#614858

It's unnecessary to present a Front End filter, if we want to force their usage either way.
In those cases, we can fallback to a Query Filter, where the value is passed already to the Query before it reaches the front end.

Now, you seem to need a less strict validation, whereas you require only to choose at least some terms.
This is as well not possible in Toolset.

What you can do, is use Custom JS for example and show the entire results only if the user actually checked at least one box.
It's not possible within Toolset using native functions.
(Example: https://stackoverflow.com/questions/901712/how-to-check-whether-a-checkbox-is-checked-in-jquery)

The search will always allow to freely search by all terms existing.
The Custom Query instead will narrow dow the results without the choice for the end user to alter this.