Comments (10)
@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.
Possibly the example just needs to be updated/fixed...
from svelte-forms-lib.
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.
Well, I can't reproduce in CodeSandbox, so it must have been a problem on my end. Closing for now.
from svelte-forms-lib.
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:
Why does it do this?
from svelte-forms-lib.
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.
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.
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.
Thanks for reporting, @TylerRick, PR here at #55. Will get this merged once we have a review.
from svelte-forms-lib.
🎉 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)
- Multiple updates and inconsistent casting
- Issue with order of validation errors when using yup validation
- OnChange (handleChange func) HOT 2
- Add support for Form Arrays for Helper Components
- $errors first string, then array HOT 1
- Prototype Pollution
- Document best practices for handling form submission
- View 'global' error on validationSchema's yup object
- Uncaught (in promise) TypeError: Cannot read property '$$' of null HOT 3
- Validation with nested objects behaves inconsistently HOT 1
- Is this project maintained? HOT 1
- Export FormState type
- Adding useField() functionality HOT 1
- Where can I find the documentation for v2? HOT 1
- $errors is not returning error messages for simple arrays (yup.array(yup.string().require()) HOT 1
- set errors when using helpers HOT 1
- What is the correct way to update a property in touched store that is array of objects?
- Have form.reset() HOT 2
- Manually modify initialValues HOT 1
- Add alternatives to validationSchema HOT 1
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 svelte-forms-lib.