feat(examples): make v0 todo rename form editable
Turn the v0 todo row rename action into an editable generated form instead of a fixed submit value, and preserve validation/recovery behavior for blank titles. This keeps the beginner exemplar on generated form handles and user-visible recovery instead of hidden demo shortcuts. req: examples/001 req: canonical_authoring/003
This commit is contained in:
@@ -402,6 +402,13 @@ mod auth_handlers {
|
|||||||
|
|
||||||
fn rename_todo_effect(state: Arc<ExampleState>, form: RenameTodo) -> impl IntoEffect {
|
fn rename_todo_effect(state: Arc<ExampleState>, form: RenameTodo) -> impl IntoEffect {
|
||||||
// req: examples/001 req: canonical_authoring/003
|
// req: examples/001 req: canonical_authoring/003
|
||||||
|
if form.title.as_str().is_empty() {
|
||||||
|
return Some((
|
||||||
|
todo_row::rename_todo_form.focus("title"),
|
||||||
|
todos::notice.set("Add a title before renaming"),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
let mut todos = state.todos.lock().unwrap();
|
let mut todos = state.todos.lock().unwrap();
|
||||||
todos
|
todos
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
@@ -710,6 +717,20 @@ mod tests {
|
|||||||
assert!(add.payload_contains("Added Ship v0"));
|
assert!(add.payload_contains("Added Ship v0"));
|
||||||
assert!(add.resets_form(todos::new_todo));
|
assert!(add.resets_form(todos::new_todo));
|
||||||
|
|
||||||
|
let rename_validation = inspect_batch(
|
||||||
|
InteractionRequest::from(form(
|
||||||
|
todo_row::rename_todo,
|
||||||
|
&[("id", "1"), ("title", " ")],
|
||||||
|
))
|
||||||
|
.dispatch_async(handlers(state.clone()))
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.batch,
|
||||||
|
);
|
||||||
|
assert_eq!(state.todos.lock().unwrap()[0].title, "Ship v0");
|
||||||
|
assert!(rename_validation.payload_contains("Add a title before renaming"));
|
||||||
|
assert!(rename_validation.updates_text(todos::notice));
|
||||||
|
|
||||||
let rename = inspect_batch(
|
let rename = inspect_batch(
|
||||||
InteractionRequest::from(form(
|
InteractionRequest::from(form(
|
||||||
todo_row::rename_todo,
|
todo_row::rename_todo,
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
<li +data-key="self.id">
|
<li +data-key="self.id">
|
||||||
<span>{+ self.title +}</span>
|
<span>{+ self.title +}</span>
|
||||||
<form data-hemx-handle="rename_todo">
|
<form data-hemx-handle="rename_todo" data-hemx-form="rename_todo">
|
||||||
<input type="hidden" name="id" +value="self.id">
|
<input type="hidden" name="id" +value="self.id">
|
||||||
<button type="submit" name="title" value="Renamed todo">Rename</button>
|
<label>
|
||||||
|
Rename
|
||||||
|
<input name="title" +value="self.title" required="required">
|
||||||
|
</label>
|
||||||
|
<button type="submit">Save</button>
|
||||||
</form>
|
</form>
|
||||||
<form data-hemx-handle="delete_todo">
|
<form data-hemx-handle="delete_todo">
|
||||||
<button type="submit" name="id" +value="self.id">Delete</button>
|
<button type="submit" name="id" +value="self.id">Delete</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user