How to contrainst a thing when that day is already booked?

Hey guys, its been too long since I’ve used bubble, so, a bit of a silly question here… I’ve made a organizational app for booking rooms at night. Its 95% done, but I still didn’t figure out the best way to show the rooms available.

  • Captura de tela de 2022-07-30 18-05-26
    I need the room dropdown to only show the rooms that available, that is, that don’t have any booking between the start date and the end date.

The current way I do this, is to save all days between start and end date in each booking. Then in the form’s dropdown, I can constraint the “Do a search for Rooms” for bookings that dosn’t contain “do a search for Bookings” that list of days. But this is too slow and seems wrong at all angles… Do you know of a better idea to do this?

*It’s night booking. So I can start a new booking today (afternoon) even if that room had a booking ending today(this morning). I don’t know if that makes a difference…

@Viktor
I think you need to use date ranges.
Here is the link which quietly resemble your scenario

1 Like

Thanks @viquarahmed07. I did look in to range option but I think I misunderstood its explanation. I will look deeper with videos and such, maybe I’m just too slow today hahah. Thanks for your time during the weekend, mate!

Hi @Viktor :wave:

Ok, I assume you have a datatype called Rooms with all your rooms…

Every booking should have

  • Room (Type = Room)
  • Check-in Date (Type = Date)
  • Check-out Date (Type = Date)

To find the availables rooms you will have to know the ones that are already booked in the period between your Datepickers.

You will have to do two searches.

→ The first one to find the Bookings where the Check-in dates are before Datepicker1’s Value and the Check-out dates are after Datepicker2’s Value

Do a Search for Bookings:each item's Room

→ The second one to find the Bookings where the Check-in dates are before Datepicker2’s Value and the Check-out dates are after Datepicker2’s Value

Do a Search for Bookings:each item's Room

Merging these to searches, you will have all the blocked rooms.

Do a Search for Bookings:each item's Room merged with Do a Search for Bookings:each item's Room

Save this list in a custom state called “Blocked rooms”.

Now, in your Dropdown, you just need to show All Rooms (just do a Search for Rooms without any constraint) minus the Blocked rooms list.

Search for Rooms:minus list Blocked rooms

This should work :+1:

2 Likes

Thank you so much for your time, mate! I’m trying to test this out but I’m struggling even with a paid course. Jesus, I feel so dumb right now…

Relax :sweat_smile:

Let’s make it together…

In what part are you stuck in?

This topic was automatically closed after 70 days. New replies are no longer allowed.