diff options
author | 2021-02-08 19:29:37 +0200 | |
---|---|---|
committer | 2021-02-08 19:29:37 +0200 | |
commit | 7075e8579e5aa038438be9bbb2ba275d52c20910 (patch) | |
tree | 87140512e8d6d4cdebb88b40e76f741c7dae38db /src/pages | |
parent | Rename invalid field IDs variable (diff) |
Implement focusing text fields if empty on submit
Diffstat (limited to 'src/pages')
-rw-r--r-- | src/pages/FormPage.tsx | 6 |
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; } |