<form> onSubmit within <DialogContent> not triggered by children <TextFields>
See original GitHub issue- This is a v1.x issue.
- This is a v3.x issue.
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
Form within dialog content should submit when you press enter on textfields inside it.
Current Behavior
Form within dialog content does not submit.
Steps to Reproduce
- Put a
form
within a dialog content. - Put a
TextField
within that form. - Add an
onSubmit
handler as props of that form. - Run it live, open the dialog, type something on the textfields, press enter
- It should submit, but it won’t.
Test Case:
- https://codesandbox.io/s/3yr35p840p
- https://3yr35p840p.codesandbox.io/
- it should
alert('form submit!');
when you press enter within the textfields but it won’t
Context
- The function, when executed through the button, works.
- The
onSubmit={(e) => {e.preventDefault(); executeSomething();}}
works in other pages of the app. - I have tried adding an id to the form, then executing
$('#loginForm').submit();
on the console… it works, so it tells me that the onSubmit handler has latched on appropriately but it appears that the elements inside it fails to see it? (not sure).
<Dialog
fullScreen={fullScreen}
open={loginFormVisibility}
onClose={toggleLoginForm}
aria-labelledby="form-dialog-title"
>
<DialogTitle id="form-dialog-title">
Log in
</DialogTitle>
<DialogContent>
<DialogContentText>
Please enter your account number and password.
</DialogContentText>
<form
id="loginForm"
onSubmit={(e) => {
console.log('form submit!');
e.preventDefault();
executeLogin();
}}
>
<TextField
autoFocus
inputProps={{
className: classes.accountNumberInput,
}}
margin="dense"
value={username}
label="Account Number"
type="text"
onChange={setUsername}
fullWidth
/>
<TextField
margin="dense"
value={password}
label="Password"
type={passwordVisibility === true ? 'text' : 'password'}
onChange={setPassword}
fullWidth
/>
</form>
<FormControlLabel
control={(
<Checkbox
checked={passwordVisibility}
onChange={togglePasswordVisibility}
color="primary"
/>
)}
label="show password"
/>
</DialogContent>
<DialogActions>
<Button onClick={toggleLoginForm} color="primary">
Cancel
</Button>
<Button onClick={executeLogin} color="primary" variant="contained">
Log in
</Button>
</DialogActions>
</Dialog>
Your Environment
Tech | Version |
---|---|
Material-UI | v3.0.0 |
React | 16.4.1 |
Browser | Chrome x64 latest |
TypeScript | nopes |
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
<form> onSubmit within <DialogContent> not triggered by ...
Put a TextField within that form. Add an onSubmit handler as props of that form. Run it live, open the dialog, type something...
Read more >Form inside Material UI dialog call submit of the form outside ...
What I'm expecting is that the form outside dialog should not be called, when submitting form inside dialog. The behavior is unexpected since ......
Read more >react-hook-form nested form | The AI Search Engine You Control
I've tried using separate useForm on each but it looks like validation is still connected with each other. So the parent form gets...
Read more >Input Components - React-admin - Marmelab
Callback taking the input value and name of the field, and returns the value you want stored in the form state. See the...
Read more >React Admin Modal: Create Record Without Leaving Page
A step-by-step example of how to create record using React modal. Create & add a record without leaving the page. React code inluded....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
See #13253
Oh my fucking god thanks for enlightening me!