Now that I’m looking at your screen closer, the ‘every possible combination’ method will be impractical. Especially since it looks like you’ve got multiple selections allowed for Category and Location.
So, here’s how I did it. I’ll assume you have a page called ClassSearch, a Repeating group called RGClasses a thing called Class and each Class has a ClassDate, Category, and Location.
The idea is to have a state on the page of a list of classes. Let’s call it ClassList. The default should be empty.
When Button is clicked,
- Set state ClassList to nothing (this may not be the first time they’ve clicked the button)
- Set state ClassList to Search for Class with no constraints (I know this is not a good idea, we’ll re-visit this later - just go with it for now).
- Set state of ClassList to Search for Class where ClassDate > FromDate’s value intersect with ClassSearch’s ClassList, only when FromDate is not empty
- Set state of ClassList to Search for Class where ClassDate < ToDate’s value intersect with ClassSearch’s ClassList, only when ToDate is not empty
- Set state of ClassList to Search for Class where Category is in Category Selected List intersect with ClassSearch’s ClassList, only when Category Selected List:count is not 0
- Set state of ClassList to Search for Class where Location is in Location Selected List intersect with ClassSearch’s ClassList, only when Location Selected List:count is not 0
- Display List in RGClasses. Data Source = ClassSearch’s ClassList
Intersect with is the key here. You start with a big list, then narrow it down for each constraint selected.
The big issue here is with #2. It is not recommended. It could horribly increase the load time of your page to return all Classes. It will help if you return only future classes, but it’s still not recommended. The solution is to not start with all records, start it with one of your constraints. That means set the state of ClassList without the intersects with clause. The trouble here is, how do you know if the constraint you’re calculating is the first one that’s not empty?
So for each check of your constraints, add another step that checks if ClassList is empty.
Let’s apply this to step 3:
3) Set state of ClassList to Search for Class where ClassDate > FromDate’s value intersect with ClassSearch’s ClassList, only when FromDate is not empty and ClassSearch’s ClassList:count is not 0
3.5) Set state of ClassList to Search for Class where ClassDate > FromDate’s value, only when FromDate is not empty and ClassSearch’s ClassList:count is 0
You can apply this to the rest of the steps. The nice thing about this is that you can add another search constraint by adding only two new steps to your workflow.
You might add to the end of the workflow before your Display List step just in case no constraints have been selected:
Set state of ClassList to Search for Class where ClassDate > Current date/time, only when ClassSearch’s ClassList:count is 0
That’s it! That’s the gist and should be enough to get you going.
Let me know how it goes!
K
ps: a couple of ‘gotchas’ to watch for:
- Be careful of your date constraints. You’re going to want to do a day add and drop the hours and minutes. Once you try this, you’ll probably see what I mean. There are other posts that answer the Date < Other date question.
- I’m not sure you can have a list of checkboxes. By that I mean that you can’t return a bunch of checkboxes as a list. You’re probably going to have to create a couple more states for a list of Categorys and a List of Locations.