submit form on enter

This commit is contained in:
2019-03-10 15:58:58 +03:00
parent b206cf1df2
commit 8d112e1339
2 changed files with 8 additions and 4 deletions

View File

@@ -36,7 +36,8 @@ export class LoginComponent extends React.PureComponent<
this.props.history.push("/signup"); this.props.history.push("/signup");
} }
public submit() { public submit(e: React.FormEvent<any>) {
e.preventDefault();
const { username, password } = this.state; const { username, password } = this.state;
if (!this.props.inProgress) { if (!this.props.inProgress) {
this.props.login(username, password); this.props.login(username, password);
@@ -52,7 +53,7 @@ export class LoginComponent extends React.PureComponent<
return ( return (
<> <>
<Card className="AuthForm" elevation={2}> <Card className="AuthForm" elevation={2}>
<form> <form onSubmit={this.submit}>
<div className="header"> <div className="header">
<H2>Login</H2> <H2>Login</H2>
<Button <Button
@@ -88,6 +89,7 @@ export class LoginComponent extends React.PureComponent<
className="submit" className="submit"
intent="primary" intent="primary"
icon="log-in" icon="log-in"
type="submit"
onClick={this.submit} onClick={this.submit}
disabled={this.props.spinner} disabled={this.props.spinner}
> >

View File

@@ -37,7 +37,8 @@ export class SignupComponent extends React.PureComponent<
this.props.history.push("/login"); this.props.history.push("/login");
} }
public submit() { public submit(e: React.FormEvent<any>) {
e.preventDefault();
const { username, password, email } = this.state; const { username, password, email } = this.state;
if (!this.props.inProgress) { if (!this.props.inProgress) {
this.props.signup(username, password, email); this.props.signup(username, password, email);
@@ -53,7 +54,7 @@ export class SignupComponent extends React.PureComponent<
return ( return (
<> <>
<Card className="AuthForm" elevation={2}> <Card className="AuthForm" elevation={2}>
<form> <form onSubmit={this.submit}>
<div className="header"> <div className="header">
<H2>Signup</H2> <H2>Signup</H2>
<Button <Button
@@ -99,6 +100,7 @@ export class SignupComponent extends React.PureComponent<
icon="new-person" icon="new-person"
className="submit" className="submit"
intent="primary" intent="primary"
type="submit"
onClick={this.submit} onClick={this.submit}
disabled={this.props.spinner} disabled={this.props.spinner}
> >