Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f4841ab

Browse files
Show error message when FormPanel is submitted blank.
1 parent b790e21 commit f4841ab

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

‎src/actions/actions.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from Component_py.stubs import require, console # __:skip
22
from actions.types import (
3-
FETCH_ALL_TODOS, COMPLETE_TODO, DELETE_TODO, ADD_NEW_TODO,
3+
FETCH_ALL_TODOS, COMPLETE_TODO, DELETE_TODO, ADD_NEW_TODO,ADD_NEW_TODO_REJECTED,
44
REGISTER_USER, REGISTER_USER_REJECTED, LOGIN_USER, LOGOUT_USER,
55
FORM_PANEL_UPDATE, LOGIN_FORM_UPDATE, CLEAR_LOGIN_FORM
66
)
@@ -39,6 +39,14 @@ def delete_todo(id_, token):
3939

4040

4141
def add_new_todo(text, token):
42+
if not text:
43+
return {
44+
"type": ADD_NEW_TODO_REJECTED,
45+
"payload": {"response": {"data": {
46+
"message": "Please fill out the form."
47+
}}}
48+
}
49+
4250
new_todo = {"text": text}
4351
return {
4452
"type": ADD_NEW_TODO,

‎src/components/ButtonPanel.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ class ButtonPanel(Component):
1818
def on_click_add(self):
1919
text, token, form_panel_update, add_new_todo = destruct(
2020
self.props, "text", "token", "form_panel_update", "add_new_todo")
21-
if text:
22-
add_new_todo(text, token)
23-
form_panel_update("")
21+
add_new_todo(text, token)
22+
form_panel_update("")
2423

2524
def on_click_clear(self):
2625
text, form_panel_update = destruct(

‎src/components/FormPanel.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ def render(self):
2222
<FormGroup>
2323
<Label for="text_input">Enter new todo text:</Label>
2424
<Input
25-
className="no-shadow"
2625
onChange={self.on_text_change}
2726
value={self.props.text}
2827
id="text_input"
29-
placeholder="What to do?"
30-
required={required} />
28+
placeholder="What to do?" />
3129
</FormGroup>
3230
); """)

‎src/components/TodoList.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,21 @@ def componentDidMount(self):
2626
fetch_all_todos(token)
2727

2828
def on_click_complete(self, todo):
29+
complete, id_ = destruct(todo, "complete", "id")
2930
token, complete_todo = destruct(self.props, "token", "complete_todo")
3031

3132
def closure():
32-
if not todo["complete"]:
33-
complete_todo(todo["id"], token)
33+
if not complete:
34+
complete_todo(id_, token)
3435
return closure
3536

3637
def on_click_delete(self, todo):
38+
complete, id_ = destruct(todo, "complete", "id")
3739
token, delete_todo = destruct(self.props, "token", "delete_todo")
3840

3941
def closure():
40-
if todo["complete"] or window.confirm('Delete incomplete Todo?'):
41-
delete_todo(todo["id"], token)
42+
if complete or window.confirm('Delete incomplete Todo?'):
43+
delete_todo(id_, token)
4244
return closure
4345

4446
def render_checkmark(self, todo):

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /