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 {
|
||||
// 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();
|
||||
todos
|
||||
.iter_mut()
|
||||
@@ -710,6 +717,20 @@ mod tests {
|
||||
assert!(add.payload_contains("Added Ship v0"));
|
||||
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(
|
||||
InteractionRequest::from(form(
|
||||
todo_row::rename_todo,
|
||||
|
||||
Reference in New Issue
Block a user