Putting It Into Practice
In the first chapter, we created an app for managing a list of dogs. The app can create, read, and delete dogs, but it cannot update them. Let’s improve the code to support updating dogs.
Replace the contents of the public/index.html file with the HTML shown in the next example. In this version, the form element is obtained by sending a GET request to /form. This enables getting a different form content based on whether the user is currently editing a dog.
The “revealed” event is dispatched when an element comes into view in the browser window. We listen for this event on a couple of elements in order to trigger sending an HTTP request that fetches initial HTML to render.
We also need to update the form when a selection-change ...
Get Server-Driven Web Apps with htmx now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.