This episode is for members only

Sign up to access "Build an Appointment Booking System With Laravel" right now.

Get started
Already a member? Sign in to continue
Playing
32. Disabling future steps

Episodes

0%
Your progress
  • Total: 4h 49m
  • Played: 0m
  • Remaining: 4h 49m
Join or sign in to track your progress

Transcript

00:00
So since our slots automatically get loaded in, we don't really need to disable this if a date isn't chosen,
00:06
because a date is always going to be in there. But we do want to disable this section if we haven't chosen a slot. It doesn't make sense to have this in here.
00:14
What we're also going to do is fix up this flicker that you can just see here, where when we refresh the page, the date is not available just yet. So we'll fix that up as well in this episode.
00:25
OK, so let's work on the form first of all. We want to get rid of this if we don't have a time slot selected. That's really the only condition.
00:34
So what we can do is we can disable this here. We can keep this, but we just want to disable this. So we can say x show if we have a time slot available. That's really as simple as that gets.
00:46
So when I choose a time slot, we then see our booking details. Otherwise, we don't. Now, we've still got that flicker in there, and you can just about see the button flickering.
00:55
We'll fix that up in a second. Let's go ahead and do that now, because I think we are pretty much done here apart from this. OK, so let's go and apply an x cloak to this within Alpine.
01:08
Now, what this will do is it will allow you to apply a style to this cloak element to hide it completely until it's available, and then that will be removed.
01:17
So basically, if we always hide a cloak element, it will never be shown on the page with CSS. But then as soon as this cloak gets removed when Alpine initializes, then we
01:26
will see that content. So let's go ahead over to app.css, and we'll add this in here now. So we're going to say x cloak, and we
01:34
are going to set this just with pure CSS to have a display of none, and we're going to make that important. We could do that with Tailwind, but let's just
01:43
keep things simple. So now what's going to happen is when we refresh the page, that element is going to have x cloak on it, so it's never going to be shown.
01:51
And it will only be shown when Alpine initializes, but after Alpine is initialized, our x show will kick in. Therefore, we won't see that flicker,
02:00
and you can see that we just don't see the button at all. Now, we could do the same thing with the slots as well. So let's go and set x cloak on our slots. So we do see a little bit of flicker here,
02:12
but that's kind of natural because we don't have any content in there, and then we're making an AJAX request and showing this. But we could add some if statements around that,
02:20
increase the height of it, add some sort of loading place holder if you wanted to. But I think the most important part of this is done. We land on here, we see the current day, we choose a time,
02:31
and we can enter our details and book. So now that we have just tidied that up a little bit, let's go and have the ability to enter our booking details and actually create an appointment in the database.

Episode summary

In this episode, we focus on improving user experience when booking appointments. We start by ensuring that the booking form section only appears once a time slot is selected—preventing users from seeing or interacting with the booking form until it's actually relevant. This helps keep the interface clean and intuitive.

Next, we deal with a common UI issue: flickering elements on page load. When fetching data asynchronously (like our available dates and slots), you might notice form sections or buttons appear briefly before disappearing or rendering properly. To solve this, we use Alpine.js's x-cloak directive, along with a simple CSS rule, to completely hide elements from view until Alpine has finished initializing and is ready to properly display them. Goodbye, UI flicker!

Lastly, we talk through ways of handling the brief empty state while your slots are loading—suggesting you could add a placeholder or a minimum height to help the page look smoother during loading. With all these small tweaks, our booking form looks and behaves much better, setting us up to move on to actually saving appointments to the database next.

Episode discussion

No comments, yet. Be the first!