todomvc example: Disallow entering empty items (#3193)

It was possible to add an empty entry by typing whitespace into the
text field. This fixes that by trimming the string *before* we check
whether it's empty.
This commit is contained in:
Martin Vilcans 2023-04-02 08:57:31 +02:00 committed by GitHub
parent b82021c455
commit 86b6cb4949
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -45,9 +45,10 @@ impl Component for App {
fn update(&mut self, _ctx: &Context<Self>, msg: Self::Message) -> bool {
match msg {
Msg::Add(description) => {
let description = description.trim();
if !description.is_empty() {
let entry = Entry {
description: description.trim().to_string(),
description: description.to_string(),
completed: false,
editing: false,
};