How to Create List Combining Optionset With Data?

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.

Hey @antony.hodgson

From my understanding in your previous post, you were referring to 96 different available slots per day (15 minutes slots basically).
In this post it seems to me you’re looking to prevent the user from booking a slot on any day where at least one 15min booking already exists?

This means if a user had booked the 8.00-8.15AM slot on 25/5/2020, other users wouldn’t be able to book any other time on that day. Is that what you’re trying to do?
Wouldn’t it make more sense to let the user pick a day, and then prevent booking on slots that are already booked?

The logic would be the same eventhough the setup wouldn’t

Hi @ambroisedlg - thanks again for replying. In my previous post, I was talking about having multiple slots on different days. Here, I was trying to work out a simplified problem (or, at least, one that was a bit easier to explain). You’re right that the core issue is the same - here, how to let a user book a day that isn’t already booked (I partly switched so that I only have 7 elements in my Repeating Group). Hope this makes sense, and sorry for any confusion.

You had originally suggested doing a Search for Booking:count > 0 (with constraints constrained with Business=Business and Current cell’s date range overlaps with Current’s cell’s Appointment’s Slot’s date range). I did originally succeed in doing a search-based approach, but when I tried that, I didn’t have the Booking included as a field within Business, so Bubble was searching an independent table. I found that, while this worked, it took 30 seconds to compute the populated list, even with only a half a dozen entries in my database, so I abandoned this.

However, I just tried this again (with Bookings now a field in Business), and it worked great - the search returned almost instantaneously. I’ll have to think more carefully about the difference between what I first tried and this, but for now my problem is solved. Thanks again!

1 Like

Awesome, happy you got it working the way you want to! Feel free to PM me if you need any further help as I’ve gone through the same hassle :slight_smile:

Thanks so much - will do (re: PM) if needed.