-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(Form): automatically focus the first field with an error upon submission failure #6547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v4
Are you sure you want to change the base?
Changes from 3 commits
98dda9d
b67b3f6
86509cf
9f0870e
f6e7caa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import type { StandardSchemaV1 } from '@standard-schema/spec' | ||
| import type { Struct } from 'superstruct' | ||
| import type { FormSchema, ValidateReturnSchema } from '../types/form' | ||
| import type { FormErrorWithId, FormSchema, ValidateReturnSchema } from '../types/form' | ||
|
|
||
| export function isSuperStructSchema(schema: any): schema is Struct<any, any> { | ||
| return ( | ||
|
|
@@ -114,3 +114,17 @@ export function setAtPath<T extends object>( | |
|
|
||
| return data | ||
| } | ||
|
|
||
| let timeOut: NodeJS.Timeout | null = null | ||
| export function scrollToErrorEl(errors: FormErrorWithId[]) { | ||
| const error = errors[0] | ||
| if (error) { | ||
| const el = document.getElementById(error.id!) | ||
| if (el) { | ||
| if (timeOut) clearTimeout(timeOut) | ||
| timeOut = setTimeout(() => { | ||
| el.focus() | ||
| }, 0) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why cant we use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's because when we submit the Form the field become |
||
| } | ||
| } | ||
| } | ||
|
rdjanuar marked this conversation as resolved.
|
||
Uh oh!
There was an error while loading. Please reload this page.