Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 73df2da

Browse files
committed
Add back trim
1 parent 918dd80 commit 73df2da

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

site/src/components/Form/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export * from "./FormDropdownField"
66
export * from "./FormTextField"
77
export * from "./FormTitle"
88

9-
export function getFormHelpers<T>(form: FormikContextType<T>, name: keyof T) {
9+
export function getFormHelpers<T>(form: FormikContextType<T>, name: keyof T) {
1010
const touched = form.touched[name]
1111
const errors = form.errors[name]
1212
return {
@@ -16,3 +16,10 @@ export function getFormHelpers<T>(form: FormikContextType<T>, name: keyof T) {
1616
helperText: touched && errors
1717
}
1818
}
19+
20+
export function onChangeTrimmed<T>(form: FormikContextType<T>) {
21+
return (event: React.ChangeEvent<HTMLInputElement>) => {
22+
event.target.value = event?.target?.value?.trim()
23+
form.handleChange(event)
24+
}
25+
}

site/src/components/SignIn/SignInForm.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Welcome } from "./Welcome"
77
import FormHelperText from "@material-ui/core/FormHelperText"
88
import { LoadingButton } from "./../Button"
99
import TextField from "@material-ui/core/TextField"
10-
import { getFormHelpers } from "../Form"
10+
import { getFormHelpers, onChangeTrimmed } from "../Form"
1111

1212
/**
1313
* BuiltInAuthFormValues describes a form using built-in (email/password)
@@ -71,6 +71,7 @@ export const SignInForm: React.FC<SignInFormProps> = ({ isLoading, authErrorMess
7171
<form onSubmit={form.handleSubmit}>
7272
<TextField
7373
{...getFormHelpers<BuiltInAuthFormValues>(form, "email")}
74+
onChange={onChangeTrimmed(form)}
7475
autoFocus
7576
autoComplete="email"
7677
className={styles.loginTextField}

0 commit comments

Comments
 (0)