-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Open
Copy link
Description
Describe the problem
- Submit form with intentionally invalid values
- Invalid fields will have
issues
- Submit form again but make sure it's valid
- If
error
is used insideform
, fieldsissues
are not updated even though validation passes
Enhanced form:
<form {...createPost.enhance(async ({ submit }) => {
try {
await submit()
} catch (error) {
console.log('oh wow, we have an error')
}
})}>
<input {...createPost.fields.title.as('text')}>
{#if createPost.fields.title.issues()}
<p>{createPost.fields.title.issues()!.at(0)!.message}</p>
{/if}
</form>
Remote form
:
export const createPost = form(
object({
title: pipe(string(), nonEmpty())
}),
async (data) => {
const currentUser = await getCurrentUser()
if (!currentUser) {
return error(401)
}
// proceed
}
)
Describe the proposed solution
Field issues
should be updated even with error
since validation passes and handler is executed
Alternatives considered
Current workaround is to manually validate
in catch
:
<form {...createPost.enhance(async ({ submit }) => {
try {
await submit()
} catch (error) {
await createPost.validate({ includeUntouched: true })
}
})}>
Importance
would make my life easier
Additional Information
@sveltejs/kit - 2.46.1
svelte - 5.39.9
Copilot