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

Boolean filter sometimes needs three states: true, false, and "don't include in filter" #324

Closed
tmecklem opened this issue Apr 19, 2022 · 4 comments

Comments

@tmecklem
Copy link

tmecklem commented Apr 19, 2022

I have a record with a valid boolean field on it. I need to be able to filter based on valid: true, valid: false, and also to choose not to filter on it at all. If I use the filter_boolean_input, it includes valid: false as filter criteria when I'm trying to filter on some other field.

For example: I searched on just the name contains criteria. It's showing two invalid companies in my results, but there's a third valid: true company that I need to be able to see as well (see second image). H

Is there a select or other boolean filter helper that accomplishes this? (Thinking something like a select with three options: true, false, and the default of "do not filter")

Screen Shot 2022-04-19 at 5 36 01 PM

Screen Shot 2022-04-19 at 5 37 30 PM

@cpjolicoeur
Copy link
Member

cpjolicoeur commented Apr 20, 2022

@tmecklem This has always been an interesting UI/UX "problem" to tackle. The checkbox/3 element from Phoenix.HTML that Torch uses under the hood to build has options for whether or not to include the hidden DOM element to submit (as well as customizing the checked/unchecked values) but Torch itself doesn't include those options in its filter_boolean_input/3 filter element.

The issue at hand is knowing when the users intention is to actually filter on the "falsey" value or their intention is to not filter on that value at all, and with a binary state input that is a hard to decipher as you pointed out. If we utilize the option to not include a hidden input for "falsey" values, then you'd only ever be able to filter on a boolean field in the truthy direction, never in the falsey.

We potentially could add a new filter_boolean_select/3 method, much like we have filter_date_select/3 and number_filter_select/3 to use instead of the more generic filter_select/3 which is currently designed to mostly only work with text based fields. We could use a select input with "True | False | Either" values which would work, presumably.

Or perhaps there can be an additional UI/UX element for the torch user to indicate that the boolean (or other) filters are "active" in the search filtering or "inactive" so they don't get sent/included.

Perhaps we use a radio button with 3 states instead? Not sure radio is ideal, and select input is probably better.

Thoughts?

@cpjolicoeur
Copy link
Member

@tmecklem To get the ball rolling, since you didn't have any feedback, I'm going to proceed with changing boolean inputs to a "three-state" select dropdown instead of the current checkbox.

@cpjolicoeur
Copy link
Member

@tmecklem

Torch version 3.9.0 and version 4.1.0 have both been released to hex.pm which should address this issue.

@tmecklem
Copy link
Author

tmecklem commented May 4, 2022

@cpjolicoeur I'm sorry I went silent for a while after submitting the issue. Thank you so much for resolving it with a fix! I think that solution works well for the use case.

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