Giter VIP home page Giter VIP logo

Comments (5)

pablo-abc avatar pablo-abc commented on August 26, 2024 1

I'll close this since the issue described here is already solved. And that I feel not including yup bundled with validator-yup is the best approach now.

Thanks a lot for your input!

from felte.

pablo-abc avatar pablo-abc commented on August 26, 2024

Hi! Thanks for giving Felte a try. It seems I've made a huge mistake in the docs regarding Yup. I'll update that ASAP. (I added the part about yup in a rush).

First of all, yup's validate function is asynchronous, so the reason it throws as an Uncaught Promise is because it's not being awaited in the validate function.

Second (and this is my mistake if you were doing this based on the docs), yup rejects with a ValidationError instance that doesn't match what Felte expects. A way to make it work (if your data object is not deep like here) is with a validate function like this one:

    validate: async (values) => {
      try {
        await schema.validate(values, { abortEarly: false });
      } catch(err) {
        const errors = err.inner.reduce((res, value) => ({
          [value.path]: value.message,
          ...res,
        }), {});
        return errors;
      }

Adding a package to handle yup's validation was in my roadmap, so this issue might as well push me into making one now. 😅.

It seems both of these might be what's causing the other issue you're experiencing in #3

Try this out and let me know if it keeps not working!

from felte.

pablo-abc avatar pablo-abc commented on August 26, 2024

Just so you know, I've create a package to help with yup validation and updated the CodeSandbox demo to show its usage.

from felte.

websocket98765 avatar websocket98765 commented on August 26, 2024

This one works great! And is nice and clean. Thank you.

Given that validator-up imports yup already, what if it also exported it too to reduce lines of code needed by the user to just this?

  import { validateSchema, yup } from '@felte/validator-yup';

from felte.

pablo-abc avatar pablo-abc commented on August 26, 2024

It's only using yup as a peerDependency. I didn't want to tie a specific version of yup to validator-yup (the same logic as I did with the reporter-tippy package) since someone might want to use their own version of yup somewhere else unrelated to Felte.

from felte.

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.