question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

<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

  1. Put a form within a dialog content.
  2. Put a TextField within that form.
  3. Add an onSubmit handler as props of that form.
  4. Run it live, open the dialog, type something on the textfields, press enter
  5. It should submit, but it won’t.

Test Case:

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:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
oliviertassinaricommented, Jul 16, 2020

See #13253

1reaction
davalaparcommented, Sep 6, 2018

Oh my fucking god thanks for enlightening me!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found