Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you make search fields optional? #24

Closed
davidyell opened this issue Jul 9, 2015 · 2 comments
Closed

Can you make search fields optional? #24

davidyell opened this issue Jul 9, 2015 · 2 comments

Comments

@davidyell
Copy link
Member

Scenario
I have a blog with posts, tags and categories. A post doesn't have to be in a category. My filter form includes a like match for the title, and a dropdown of categories with 'empty' => true, using a value match on category_id.

Generated url possibilities
example.com/posts?q=welcome - Return posts containing 'welcome'
example.com/posts?q=welcome&category=8 - Return posts in category 8 with welcome in the title
example.com/posts?q=welcome&category= - Returns no results

Sidestep
So far the only way I can find to sidestep this is to use a custom find and check the $options array param for empty() and ignore it if it's empty.

Ideally
The CakeDC/search had a nice way of just marking a filter field as allowed to be optional, which would exclude it from searches if it was empty. Something like this would be ideal for scenarios where you want to filter using optionally null data.

@davidyell davidyell changed the title How to make search fields optional? Can you make search fields optional? Jul 9, 2015
@jippi
Copy link
Member

jippi commented Jul 9, 2015

seems like a easy fix - check the value for empty and allowEmpty and don't append it to the query

@davidyell
Copy link
Member Author

Thanks guys! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants