Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add input validation for empty task input field #59

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions examples/todo_series/beginner/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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()