Skip to content

Commit a298c27

Browse files
committed
Add input validation for empty task input field
1 parent 9191d7b commit a298c27

File tree

1 file changed

+8
-2
lines changed
  • examples/todo_series/beginner

1 file changed

+8
-2
lines changed

examples/todo_series/beginner/app.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ def __ft__(self:Todo):
2323
hx_swap='outerHTML')
2424
return Li(show, ' | ', delete, id=tid(self.id))
2525

26-
def mk_input(**kw): return Input(id="new-title", name="title", placeholder="New Todo", **kw)
26+
def mk_input(**kw):
27+
return Input(
28+
id="new-title", name="title", placeholder="New Todo",required=True,**kw
29+
)
2730

2831
@rt
2932
async def index():
@@ -34,6 +37,9 @@ async def index():
3437
return Title(title), Main(H1(title), card, cls='container')
3538

3639
@rt
37-
async def insert_todo(todo:Todo): return todos.insert(todo), mk_input(hx_swap_oob='true')
40+
async def insert_todo(todo:Todo):
41+
if not todo.title.strip():
42+
return mk_input(hx_swap_oob='true')
43+
return todos.insert(todo), mk_input( hx_swap_oob='true')
3844

3945
serve()

0 commit comments

Comments
 (0)