htmx/www/content/examples/click-to-edit.md
Denis Palashevskii 18aa2470a0
fix accesibility and keyboard navigation issues in examples (#1433)
* fix accesibility and keyboard navigation issues in examples

* fix review comments

* remove redundant aria attributes, remove redundant autofocus

* rework progress bar demo's accesibility

* rework tabs HATEOS example to be more ARIA compliant

* rework tabs _hyperscript example to be ARIA compliant
2023-06-30 11:28:54 -05:00

3.1 KiB

+++ title = "Click to Edit" template = "demo.html" +++

The click to edit pattern provides a way to offer inline editing of all or part of a record without a page refresh.

  • This pattern starts with a UI that shows the details of a contact. The div has a button that will get the editing UI for the contact from /contacts/1/edit
<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="/contact/1/edit" class="btn btn-primary">
    Click To Edit
    </button>
</div>
  • This returns a form that can be used to edit the contact
<form hx-put="/contact/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/1">Cancel</button>
</form>
  • The form issues a PUT back to /contacts/1, following the usual REST-ful pattern.

{{ demoenv() }}