Comments (5)
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.
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.
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.
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.
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)
- Svelte CodeSandbox demo doesn't compile
- setData does not update inputs' value HOT 2
- Unexpected `key` in mixed in with data
- @felte/validator-vest update dependencies for vest
- Simplify return type of `createForm` HOT 1
- Array lists don't work with Solid.js HOT 2
- SvelteKit: errors from server are treated as success HOT 4
- Expose / export default submit handler directly, or through context / callbacks
- response undefined in onSuccess HOT 1
- Field Array errors result is exclude null entries after invaild value submitted
- Form validation errors not visible in DOM HOT 1
- The demo about solid was wrong
- How to prevent validation if form is not dirty? HOT 2
- error store is empty , but isValid is false HOT 1
- Solid use:form directive showing an error in VSCode?
- vest async validator promisify
- Nested forms update the parent data store HOT 1
- I can't use PUT on form method
- ValidationMessage should be a SvelteComponentTyped
- Set a field's value to undefined
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from felte.