Skip to content

Commit 8167084

Browse files
committed
Merge pull request #1394 from tonyspiro/master
examples form onsubmit
2 parents abcf6c2 + 563d7c2 commit 8167084

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

docs/basics/ExampleTodoList.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,21 @@ let AddTodo = ({ dispatch }) => {
347347

348348
return (
349349
<div>
350-
<input ref={node => {
351-
input = node
352-
}} />
353-
<button onClick={() => {
350+
<form onSubmit={e => {
351+
e.preventDefault()
352+
if (!input.value.trim()) {
353+
return
354+
}
354355
dispatch(addTodo(input.value))
355356
input.value = ''
356357
}}>
357-
Add Todo
358-
</button>
358+
<input ref={node => {
359+
input = node
360+
}} />
361+
<button type="submit">
362+
Add Todo
363+
</button>
364+
</form>
359365
</div>
360366
)
361367
}

examples/todos-with-undo/containers/AddTodo.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,21 @@ let AddTodo = ({ dispatch }) => {
77

88
return (
99
<div>
10-
<input ref={node => {
11-
input = node
12-
}} />
13-
<button onClick={() => {
10+
<form onSubmit={e => {
11+
e.preventDefault()
12+
if (!input.value.trim()) {
13+
return
14+
}
1415
dispatch(addTodo(input.value))
1516
input.value = ''
1617
}}>
17-
Add Todo
18-
</button>
18+
<input ref={node => {
19+
input = node
20+
}} />
21+
<button type="submit">
22+
Add Todo
23+
</button>
24+
</form>
1925
</div>
2026
)
2127
}

examples/todos/containers/AddTodo.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,21 @@ let AddTodo = ({ dispatch }) => {
77

88
return (
99
<div>
10-
<input ref={node => {
11-
input = node
12-
}} />
13-
<button onClick={() => {
10+
<form onSubmit={e => {
11+
e.preventDefault()
12+
if (!input.value.trim()) {
13+
return
14+
}
1415
dispatch(addTodo(input.value))
1516
input.value = ''
1617
}}>
17-
Add Todo
18-
</button>
18+
<input ref={node => {
19+
input = node
20+
}} />
21+
<button type="submit">
22+
Add Todo
23+
</button>
24+
</form>
1925
</div>
2026
)
2127
}

0 commit comments

Comments
 (0)