In this episode, we focus on making our app a bit more interactive by updating the selected date in our form when a user picks a new one. Up to this point, if you changed the date on the date picker, nothing actually happened—the form wasn’t aware that you’d chosen something new!
So, we fix this by listening for the change event when a date is selected. We tweak our Alpine directive to emit a custom select
event whenever a new date is picked. By logging details to the console, we can verify that our event includes the selected date (in the right format).
Back on the form side, we hook into this custom event using Alpine’s x-on:select
, and instead of just logging things, we wire it up to a new method that updates the form’s date property in our Livewire component. Now, the displayed date changes as soon as you pick a new one—progress!
Now, when a user chooses a date, it’s reflected immediately in the form data, making sure the rest of our booking process will have the correct date every time.