Skip to content
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

[BUG] First example in the documentation does not work #95

Open
alexspurling opened this issue Nov 18, 2022 · 3 comments · May be fixed by #106
Open

[BUG] First example in the documentation does not work #95

alexspurling opened this issue Nov 18, 2022 · 3 comments · May be fixed by #106
Assignees
Labels
bug Something isn't working

Comments

@alexspurling
Copy link

In the first example in the documentation of a simple form, the input field is considered to be valid on first load even though no value exists in the field.

I have slightly adapted the first example to demonstrate the problem:

https://svelte.dev/repl/7aca3afc2c374c7e9c143e773fbdc0ef?version=3.53.1

I would expect the form to show "Form valid: false". Instead it says "Form valid: true"

Screenshot from 2022-11-18 10-17-35

I am using version 2.3.1 of svelte-forms.

@alexspurling alexspurling added the bug Something isn't working label Nov 18, 2022
@philippone
Copy link

philippone commented Dec 22, 2022

It seems that validation is only triggered when all fields are dirty.

Unfortunately, that's too late and you could submit an invalid form with empty but required fields.

@BrianIto
Copy link

BrianIto commented Jan 8, 2023

Big bug actually. I really don't know how about anyone didn't care about it.

Not a fix, but a good workaround is:

import { onMount } from "svelte";

onMount(() => { myForm.validate() })

This makes the Form work properly.

@grischaerbe
Copy link

Add { checkOnInit: true } as the last argument to any of the fields used in the form:

export const name = field('name', '', [required()], {
  checkOnInit: true
})

export const accountForm = form(name)

Kelamir added a commit to Kelamir/svelte-forms that referenced this issue Feb 17, 2023
Fixes chainlist#95 

It's expected that a form would behave as if it has checkOnInit on: empty form is invalid - false, once you add some input, it's true. 
One can of course read the documentation in detail to figure out what's wrong, but it might be useful for the first example to be self-sufficient.

The change was proposed by grischaerbe in the issue, and it is already explained in documentation. Thoughts on adding this to documentation?
@Kelamir Kelamir linked a pull request Feb 17, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants