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] $myForm.hasError('email.email') not functional #105

Open
kirkbushell opened this issue Feb 4, 2023 · 1 comment
Open

[BUG] $myForm.hasError('email.email') not functional #105

kirkbushell opened this issue Feb 4, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@kirkbushell
Copy link

Describe the bug
When an email input has the email validator registered, checking for email.email error fails. The form knows its invalid, but the email validator check does not return true that it is the validation that has failed.

To Reproduce
Steps to reproduce the behavior:

  1. Setup a new field, with an email validator.
  2. Enter an invalid email, such as heythere!
  3. Note that $form.valid is false, but $form.hasError('email.email') is also false (when it should be true)

Expected behavior
$form.hasError('email.email') should return true.

Additional context
Code being used:

<input type="text" bind:value={$eml.value} class="w-full p-2 px-4 rounded focus:outline-blue-500" placeholder="Email">
{#if !$emailForm.valid}
    <div class="bg-red-500 text-white rounded-b -mt-0.5 p-0.5 pt-1 text-sm">
        {#if $emailForm.hasError('email.required')}
            <span>Email is required.</span>
        {/if}
        {#if $emailForm.hasError('email.email')}
            lkjasdflkjasf
            <span>Please provide a valid email address.</span>
        {/if}
    </div>
{/if}

<script type="ts">
    import { form, field } from 'svelte-forms';
    import { email, required } from 'svelte-forms/validators';
    
    const eml = field('email', '', [required(), email()])
    const emailForm = form(eml)
</script>

The div that highlights it all in red, is showing, but it's not showing the invalid error for the email validation.

@kirkbushell kirkbushell added the bug Something isn't working label Feb 4, 2023
@kirkbushell
Copy link
Author

Alright, I figured it out - documentation needs an update. Unfortunately, you need to know the internal error string that is raised when it errors - which is.. "not_an_email"

I would have expected it to just be "email". like "required" (same function name).

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

No branches or pull requests

2 participants