In this article we will go over how to set the ability to book appointments or reserve an item for a period of time while preventing double bookings.
This setup involves the use of Validation Rules. If you are not familiar with Validation Rules please see our support doc titled Form Validation Rules.
Let's first layout the general structure we'll be building so you can have a better understanding of the process along the way.
Say we have a car rental app. Users will go to the app in order to reserve a vehicle. We will display a calendar of all the previous bookings so users can see what the available times are. Then to make a booking, a user will select a vehicle and choose a start and end time. If the times selected conflicts with any previous bookings on the chosen vehicle, a custom message will be displayed preventing the booking from going through.
Now that we've described the structure behind the process, let's get started on actually building this all out:
The First step is to go into the data builder and add two tables: Vehicles and Bookings.
In the bookings table, we'll now add two fields:
1. Add a "Date Range" field we can call "Booking Time" and select to enable "Start and End Date"
2. Add a "Connection" field we can call "Vehicle Name". Then make the connection to the Vehicles table.
Before we move on to the page builder let's add some Vehicle records. In the Vehicles data table under the records tab, we can select to "Add New" record and enter some vehicle names.
Now let's move on to the page builder to design how we wish to display our vehicles and bookings.
In the page builder we can add a page with a Calendar component, select the Bookings data table and click to quick add. Then we can add a Form component, again selecting the Bookings data table and quick add.
Now that we have our components, let's set Validation Rules to prevent bookings from being submitted if they conflict with previous bookings. To set validation rules, click on the Add Booking Form to edit it. Once inside the form, click on Form Rules and then Validation Rules.
Once in Validation Rules, select Add New Rule, and then set a rule that if the "Date Range" field (which we have chosen to call "Booking Time") "conflicts with existing records" then display an error message preventing the form submission. This rule will work if we only have one vehicle or one item being reserved, but if we have multiple vehicles we will want to allow different vehicles to be booked for the same time.
To allow for different vehicles to be booked for the same time when we have multiple vehicles, select the plus icon to add a parameter to the rule to check that the "Connection" field (which we have chosen to call "Vehicle Name") "is not unique".
Now users can select which vehicle they would like to book and they will only be allowed to book the vehicle in the times it is available for.