Code Monkey home page Code Monkey logo

Comments (10)

larrybotha avatar larrybotha commented on May 24, 2024 1

@TylerRick you're spreading formProps onto your <form >, but formProps doesn't return onSubmit - it returns handleSubmit, and that should be supplied to the form via the on:submit DOM event handler:

<script>
  const {handleSubmit} = createForm({
    onSubmit: (values) => // do something with values,
  });
</script>

<form on:submit|preventDefault={handleSubmit}>
...

EDIT: my bad, I see you're using the Form component, not the native DOM form - ignore this comment :P

from svelte-forms-lib.

TylerRick avatar TylerRick commented on May 24, 2024

Possibly the example just needs to be updated/fixed...

from svelte-forms-lib.

TylerRick avatar TylerRick commented on May 24, 2024

Looks like createForm requires a validate function to be passed in.

Adding:

    validate: values => true

makes the error go away...

So I guess the docs just need to be updated to include that.

But better yet, maybe validate should be made to be optional? You shouldn't need a validate function if you don't want to validate anything.

from svelte-forms-lib.

TylerRick avatar TylerRick commented on May 24, 2024

Well, I can't reproduce in CodeSandbox, so it must have been a problem on my end. Closing for now.

from svelte-forms-lib.

TylerRick avatar TylerRick commented on May 24, 2024

I take that back. I did just run into it using the CodeSandbox template, so it's not just a problem with my code. But it's only intermittent. When I reload that sandbox, it doesn't give any error when I submit now.

But I did just run into it in a different Sandbox that's just as simple or simpler:

image

Why does it do this?

from svelte-forms-lib.

TylerRick avatar TylerRick commented on May 24, 2024

Yeah, I've seen the error intermittently with both Form component and using createForm — using examples straight from the docs. Strange.

from svelte-forms-lib.

TylerRick avatar TylerRick commented on May 24, 2024

Not super urgent since I'm not running into it anymore in my actual app, but just something to keep an eye out for...

from svelte-forms-lib.

larrybotha avatar larrybotha commented on May 24, 2024

This is happening because the return type of validateFieldValue is Promise | undefined, and updateValidateField assumes the return type is Promise: Here's the issue:

  function validateFieldValue(field, value) {
    updateTouched(field, true);
    if (validationSchema) {
      isValidating.set(true);
      return util.reach(validationSchema, field).validate(value).then(() => util.update(errors, field, "")).catch(error => util.update(errors, field, error.message)).finally(() => {
        isValidating.set(false);
      });
    }

    if (validateFn) {
      isValidating.set(true);
      return Promise.resolve().then(() => validateFn({
        [field]: value
      })).then(errs => util.update(errors, field, ! util.isNullish(errs) ? errs[field] : "")).finally(() => {
        isValidating.set(false);
      });
    }

	// => not handling !validationSchema && !validateFn
  }

from svelte-forms-lib.

larrybotha avatar larrybotha commented on May 24, 2024

Thanks for reporting, @TylerRick, PR here at #55. Will get this merged once we have a review.

from svelte-forms-lib.

tjinauyeung avatar tjinauyeung commented on May 24, 2024

🎉 This issue has been resolved in version 1.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

from svelte-forms-lib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.