-
Hi :) I'm very new to Svelte and SvelteKit (coming from React and Remix) and I love it ❤️ I was trying to retrieve the form submission status, so I can show some spinner and/or disable the submit button. I ended up with: <script lang="ts">
...
let isSubmitting = false;
</script>
<h1 class="mb-4">Basic information</h1>
<!-- <form method="post" use:enhance> -->
<form
method="post"
use:enhance={() => {
isSubmitting = true;
return async () => {
isSubmitting = false;
};
}}
>
... But I read on https://kit.svelte.dev/docs/form-actions#progressive-enhancement-use-enhance that:
With my current code, I understand I loose all these nice features because I specify an argument.. Which is unfortunate. Is there a way to implement an additional |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hey binajmen, You'll just need to call <script>
+ import { enhance, applyAction } from '$app/forms';
let isSubmitting = false;
</script>
<form
method="POST"
use:enhance={() => {
isSubmitting = true;
+ return async ({ result }) => {
+ await applyAction(result);
isSubmitting = false;
};
}}
> https://kit.svelte.dev/docs/form-actions#progressive-enhancement-applyaction |
Beta Was this translation helpful? Give feedback.
-
Another way <script lang="ts">
...
- let isSubmitting = false;
+ $: isSubmitting = (void form, false);
</script>
<h1 class="mb-4">Basic information</h1>
<!-- <form method="post" use:enhance> -->
<form
method="post"
use:enhance={() => {
isSubmitting = true;
- return async () => {
- isSubmitting = false;
- };
}}
>
... |
Beta Was this translation helpful? Give feedback.
Hey binajmen,
You'll just need to call
applyAction(result)
to have those same behaviours.https://kit.svelte.dev/docs/form-actions#progressive-enhancement-applyaction