From a298c279c31bf4e00585360f8295bf1da951fba1 Mon Sep 17 00:00:00 2001 From: ihasidul Date: Thu, 12 Dec 2024 00:30:00 +0600 Subject: [PATCH] Add input validation for empty task input field --- examples/todo_series/beginner/app.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/todo_series/beginner/app.py b/examples/todo_series/beginner/app.py index 1547cd4..6a2123f 100644 --- a/examples/todo_series/beginner/app.py +++ b/examples/todo_series/beginner/app.py @@ -23,7 +23,10 @@ def __ft__(self:Todo): hx_swap='outerHTML') return Li(show, ' | ', delete, id=tid(self.id)) -def mk_input(**kw): return Input(id="new-title", name="title", placeholder="New Todo", **kw) +def mk_input(**kw): + return Input( + id="new-title", name="title", placeholder="New Todo",required=True,**kw + ) @rt async def index(): @@ -34,6 +37,9 @@ async def index(): return Title(title), Main(H1(title), card, cls='container') @rt -async def insert_todo(todo:Todo): return todos.insert(todo), mk_input(hx_swap_oob='true') +async def insert_todo(todo:Todo): + if not todo.title.strip(): + return mk_input(hx_swap_oob='true') + return todos.insert(todo), mk_input( hx_swap_oob='true') serve() \ No newline at end of file