单击编辑模式提供了一种无需刷新页面即可提供对全部或部分记录进行内联编辑的方法。
¥The click to edit pattern provides a way to offer inline editing of all or part of a record without a page refresh.
此模式从显示联系人详细信息的 UI 开始。div 有一个按钮,可从 /contact/1/edit
获取联系人的编辑 UI
¥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 /contact/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 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>
表单按照通常的 REST-ful 模式将 PUT
发回 /contact/1
。
¥The form issues a PUT
back to /contact/1
, following the usual REST-ful pattern.