【发布时间】:2020-03-01 03:38:08
【问题描述】:
这是我在渲染方法中的表单,用于用户登录。
<form onSubmit={this.handleSubmit}>
<Avatar className={classes.avatar}>
<LockOutlinedIcon />
</Avatar>
<Typography component="h1" variant="h5">
Sign in
</Typography>
<TextField variant="outlined" margin="normal" fullWidth id="email"
label="Email Address" name="email" onChange={this.handleEmailChange}
/>
<TextField variant="outlined" margin="normal" fullWidth
name="password" onChange={this.handlePasswordChange}
/>
{loginError && (
<Typography component="p" className={classes.errorText}>
Incorrect email or password.
</Typography>
)}
<Button type="button" fullWidth variant="contained" color="primary"
className={classes.submit} onClick={this.handleSubmit}
>
Sign In
</Button>
</form>
以下是我的句柄提交方法。
handleSubmit = () => {
const { dispatch } = this.props;
const { email, password } = this.state;
dispatch(loginUser(email, password));
};
如何按Enter 键提交表单?我正在使用标准的 Material UI Button 组件。
【问题讨论】:
标签: javascript reactjs forms material-ui