Skip to content

Valid field issues are not cleared when error is used in remote form handler #14646

@vladshcherbin

Description

@vladshcherbin

Describe the problem

  1. Submit form with intentionally invalid values
  2. Invalid fields will have issues
  3. Submit form again but make sure it's valid
  4. If error is used inside form, fields issues 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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions