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

Filters: add ability to search for blank/null fields with boolean search #1893

Merged
merged 1 commit into from
Mar 5, 2013

Conversation

whatcould
Copy link
Contributor

Also matching just the end of the supplied field name, which should only matter in case of some strange field names but is probably a good idea just in case.

@seanlinsley
Copy link
Contributor

So how does this work? How could we use it e.x. in a index filter? I'd like to be able to search for any field that isn't empty/null.

@whatcould
Copy link
Contributor Author

I think you could already do this before this commit, with this filter:

    filter :county_is_present, as: :boolean

This commit adds the ability to do the opposite:

    filter :county_is_blank, as: :boolean

@seanlinsley
Copy link
Contributor

Eh, I'd prefer it be inline to the existing filter. Like for a string, you'd have a checkbox whether to include it, and if it's checked and the text field is empty, it will search for null and blank values.

@whatcould
Copy link
Contributor Author

Ah. I don't think that's possible without some hacking around in the filters code. Right now if the filter field is blank, that's how AA decides if the filter should be applied at all.

It would complicate the UI enough that I wouldn't want that on by default, but I could see it being added as an option to filters (eg filter :county_name, allow_blank_search: true or something).

@seanlinsley
Copy link
Contributor

In a similar vein, it would be useful to have is_blank for numeric filters :D

@macfanatic
Copy link
Contributor

@whatcould Could you post a quick screenshot of what this looks like on a resource listing page?

@whatcould
Copy link
Contributor Author

Sure. It's pretty simple; a filter for "County is blank":

    filter :county_is_blank, as: :boolean

Looks like this:

5mxv

@macfanatic
Copy link
Contributor

Would the following produce a dropdown with options of "yes" & "no"?

filter :country_is_blank, as: :select

In general, I don't think having checkboxes in the filter sidebar is a good UI choice.

@whatcould
Copy link
Contributor Author

Trying to make a boolean a select doesn't work; it tries to create a "county_is_blank_eq" filter, and that is not what you're looking for. There might be a way to hack it somehow but I suspect it would require more activeadmin hacking (and another pull request).

In this case, on my project, the user just wants to occasionally find records where the county is blank (to fill them in); there is no reason to select records where the county is not blank. This seems like a pretty common use case.

This commit is still useful regardless; it adds in some metasearch_conditions that already exist but are not accessible because they were left out of the boolean input filter.

macfanatic added a commit that referenced this pull request Mar 5, 2013
Filters: add ability to search for blank/null fields with boolean search
@macfanatic macfanatic merged commit d0df6b4 into activeadmin:master Mar 5, 2013
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

Successfully merging this pull request may close these issues.

3 participants