Skip to content

Commit f465b11

Browse files
committed
Use onSubmit for dialog forms.
1 parent 03c0bdc commit f465b11

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

demos/nextjs-supabase-todolist/src/app/views/todo-lists/edit/page.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ const TodoEditSection = () => {
122122
onClose={() => setShowPrompt(false)}
123123
aria-labelledby="alert-dialog-title"
124124
aria-describedby="alert-dialog-description"
125+
PaperProps={{
126+
component: 'form',
127+
onSubmit: async (event: React.FormEvent<HTMLFormElement>) => {
128+
event.preventDefault();
129+
await createNewTodo(nameInputRef.current!.value);
130+
setShowPrompt(false);
131+
},
132+
}}
125133
>
126134
<DialogTitle id="alert-dialog-title">{'Create Todo Item'}</DialogTitle>
127135
<DialogContent>
@@ -130,12 +138,7 @@ const TodoEditSection = () => {
130138
</DialogContent>
131139
<DialogActions>
132140
<Button onClick={() => setShowPrompt(false)}>Cancel</Button>
133-
<Button
134-
onClick={async () => {
135-
await createNewTodo(nameInputRef.current!.value);
136-
setShowPrompt(false);
137-
}}
138-
>
141+
<Button type="submit">
139142
Create
140143
</Button>
141144
</DialogActions>

demos/nextjs-supabase-todolist/src/app/views/todo-lists/page.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ export default function TodoListsPage() {
9797
<Dialog
9898
open={showPrompt}
9999
onClose={() => setShowPrompt(false)}
100+
PaperProps={{
101+
component: 'form',
102+
onSubmit: async (event: React.FormEvent<HTMLFormElement>) => {
103+
event.preventDefault();
104+
await createNewList(nameInputRef.current!.value);
105+
setShowPrompt(false);
106+
},
107+
}}
100108
aria-labelledby="alert-dialog-title"
101109
aria-describedby="alert-dialog-description"
102110
>
@@ -107,12 +115,7 @@ export default function TodoListsPage() {
107115
</DialogContent>
108116
<DialogActions>
109117
<Button onClick={() => setShowPrompt(false)}>Cancel</Button>
110-
<Button
111-
onClick={async () => {
112-
await createNewList(nameInputRef.current!.value);
113-
setShowPrompt(false);
114-
}}
115-
>
118+
<Button type="submit">
116119
Create
117120
</Button>
118121
</DialogActions>

0 commit comments

Comments
 (0)