aboutsummaryrefslogtreecommitdiffstats
path: root/src/pages
diff options
context:
space:
mode:
authorGravatar ks129 <[email protected]>2021-02-08 19:29:37 +0200
committerGravatar ks129 <[email protected]>2021-02-08 19:29:37 +0200
commit7075e8579e5aa038438be9bbb2ba275d52c20910 (patch)
tree87140512e8d6d4cdebb88b40e76f741c7dae38db /src/pages
parentRename invalid field IDs variable (diff)
Implement focusing text fields if empty on submit
Diffstat (limited to 'src/pages')
-rw-r--r--src/pages/FormPage.tsx6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/pages/FormPage.tsx b/src/pages/FormPage.tsx
index 8e998c5..50f48ba 100644
--- a/src/pages/FormPage.tsx
+++ b/src/pages/FormPage.tsx
@@ -199,7 +199,8 @@ function FormPage(): JSX.Element {
}
const questions = form.questions.map((question, index) => {
- return <RenderedQuestion ref={createRef<RenderedQuestion>()} scroll_ref={createRef<HTMLDivElement>()} question={question} public_state={new Map()} key={index + Date.now()}/>;
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ return <RenderedQuestion ref={createRef<RenderedQuestion>()} focus_ref={createRef<any>()} scroll_ref={createRef<HTMLDivElement>()} question={question} public_state={new Map()} key={index + Date.now()}/>;
});
async function handleSubmit(event: SyntheticEvent) {
@@ -223,6 +224,9 @@ function FormPage(): JSX.Element {
const firstErrored = questions[invalidFieldIDs[0]];
if (firstErrored && firstErrored.props.scroll_ref) {
firstErrored.props.scroll_ref.current.scrollIntoView({ behavior: "smooth", block: "center" });
+ if (firstErrored.props.focus_ref && firstErrored.props.focus_ref.current) {
+ firstErrored.props.focus_ref.current.focus({ preventScroll: true });
+ }
}
return;
}