Comments (1)
I also had the same problem, when trying to use the enhanced forms feature from svelte-kit.
I couldn't get it to work through default configurations but I found a workaround that I use as a pattern, when I use svelte-forms, maybe you can incorporate this in your project:
My form definition is only slightly longer in a function like so:
<script lang="ts">
export let data;
...
function createEditProfileForm() {
const firstName = field('firstName', data.userProfile?.first_name, [required()]);
const lastName = field('lastName', data.userProfile?.last_name, [required()]);
const zipCode = field('zipCode', data.userProfile?.zip_code, [required()]);
const city = field('city', data.userProfile?.city, [required()]);
const address = field('address', data.userProfile?.address, [required()]);
const editProfileForm = svelteForm(zipCode, city, address, firstName, lastName);
return { firstName, lastName, zipCode, city, address, editProfileForm };
}
function resetEditProfileForm() {
({ firstName, lastName, zipCode, city, address, editProfileForm } = createEditProfileForm());
}
let { firstName, lastName, zipCode, city, address, editProfileForm } = createEditProfileForm();
...
</script>
And the markup is like this:
...
<form action="/?someAction" use:enhance={() => {
return async ({ update }) => {
// this causes the server load function to run again without resetting the
// form. The default reset unfortunately completely clears my forms, so I
// needed to manually reset it, but with fresh values from the server.
await update({ reset: false, invalidateAll: true });
// after the update Promise resolves the PageData is refreshed,
// so I fully recreate the form. This has the additional advantage that the form is not dirty again,
// so something like disabling buttons when the user didn't do anything yet just works.
resetEditProfileForm();
};
}>
<input bind:value={$firstName.value} />
...
<button type="submit">Update Profile</button>
....
</form>
...
Either I missed something in the official docs or it's really missing, but I initially tried to find some Event, that tells me that the load functions are done executing after invalidation. Unfortunately I couldn't find something so I had to customize my enhance action.
But overall I'm very satisfied with my workaround since it only minimally affects my personal DX.
from svelte-forms.
Related Issues (20)
- [REQUEST] addField() method HOT 2
- [BUG] min validation evaluates string as number HOT 2
- [REQUEST] Be able to loop through all a field's errors
- [BUG] $myForm.hasError('email.email') not functional HOT 1
- Error names without period are not detected in hasError
- [BUG] validateOnChange prevents fields from being marked as dirty
- [BUG]: min() function doesn't work with a string of numbers only HOT 1
- [BUG] Combined function marks dirty attribute as true HOT 1
- [BUG] email validator doesn't return a form error HOT 1
- [BUG] min validator for strings not consistent HOT 2
- [BUG] matchField does not re-evaluate when the other field is changed
- [REQUEST] eitherOr validator
- [REQUEST] optional validator HOT 2
- How to handle array data type? HOT 1
- Keep input value on HRM
- [BUG] First example in the documentation does not work HOT 3
- How to modify input value before valiationOnChange? HOT 1
- Using in Astro HOT 1
- [ANNOUNCEMENT] Getting back working on svelte-forms and looking for maintainers! HOT 9
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.