The click to edit pattern provides a way to offer inline editing of all or part of a record without a page refresh.
contact.jsp
that shows the details of a contact. The div has a button that will get the editing UI for the contact from edit.jsp
<div hx-target="this" hx-swap="outerHTML">
<div><label>First Name</label>: Joe</div>
<div><label>Last Name</label>: Blow</div>
<div><label>Email</label>: joe@blow.com</div>
<button hx-get="edit.jsp?id=1" class="btn primary">
Click To Edit
</button>
</div>
<form hx-post="save.jsp?id=1" hx-target="this" hx-swap="outerHTML">
<div>
<label>First Name</label>
<input type="text" name="firstName" value="Joe">
</div>
<div class="form-group">
<label>Last Name</label>
<input type="text" name="lastName" value="Blow">
</div>
<div class="form-group">
<label>Email Address</label>
<input type="email" name="email" value="joe@blow.com">
</div>
<button class="btn">Submit</button>
<button class="btn" hx-get="contact.jsp?id=1">Cancel</button>
</form>
POST
back to save.jsp
, which acts as a stand-in for a database
update service. The page instead stores the values into a session
object before
redirecting back to contact.jsp
to display the data.