I’m trying to set up an appointments app and am running into problems trying to show the user what days are available from a certain business (for simplicity, imagine that a business can offer one service per day). When the user picks a business and specifies what week they’d like to schedule a service, I’d like to show them a repeating group of color-coded buttons showing what days in that week are available (eg, the button should be green if the day is still free, red or grey if not).
Key data elements:
- DaysOfWeek - an optionset containing Mon, Tue, Wed… (set up as optionset because it’s easy to pre-define)
- Business - used to track the different businesses that offer service
- Booking - a data structure that holds links to the User, the Business, the Week of the Booking, and the DayOfTheWeek (ie, one of the options from DaysOfWeek). Note that I’ve stored all Bookings associated with a particular Business as a list within the Business so that they’re readily retrievable once the user has selected a Business.
So far, I’ve set up a page where the user selects a Business and a Week from dropdowns. I’d then like to load a Repeating Group populated with Buttons for each day of the week, color-coded as described above (thanks to @ambroisedlg for this suggestion from another related post).
It’s easy to set up the Repeating Group with the data source set to All DaysOfWeek - this gives me the seven buttons. What I can’t figure out is how to make the button color for each day of the week conditional on whether there is or is not a Booking associated with the selected Business for that day (and Week).
I’ve experimented with using Conditionals on each cell to change the background colour, but couldn’t figure out how to phrase the condition. For example, it looks as if you can start with “Current cell’s DaysOfWeek”, but then I’m not sure how to test if this is contained deep in the Business data type. It seems that my main option at this point is to say “Current cell’s DaysOfWeek is (or is not)” something. I can find the current Business from the dropdown selector, but then I don’t know how to say “Current cell’s DaysOfWeek is the same as the DayOfTheWeek in one of this Business’s Bookings from this same Week”.
I would greatly appreciate someone pointing me in the right direction.
PS. BTW, I did wonder whether I could create a new custom state for the page when the Business is selected that was a list of a new data type (let’s call it an Availability) that contains a DayOfTheWeek and an Available flag (boolean yes/no). This list would have one entry for each DayOfTheWeek, so it could be used for the Repeating Group, and then I could set a conditional on the Available flag to modify the background color. Unfortunately, I couldn’t figure out how to create this custom state - ie, how to pull together the optionset with the Business’s list of Bookings.
