fuma 0.3.57 → 0.3.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="svelte" />
|
|
1
2
|
import type { SubmitFunction } from '@sveltejs/kit';
|
|
2
3
|
export type SetError = {
|
|
3
4
|
[key: string]: (err: string) => void;
|
|
@@ -26,6 +27,7 @@ export declare function useForm<ReturnData extends Record<string, unknown>>({ on
|
|
|
26
27
|
destroy(): void;
|
|
27
28
|
};
|
|
28
29
|
submit: SubmitFunction<ReturnData>;
|
|
30
|
+
isLoading: import("svelte/store").Writable<boolean>;
|
|
29
31
|
resetErrors: () => Promise<void>;
|
|
30
32
|
setError(key: string, value: string): void;
|
|
31
33
|
};
|
package/dist/validation/form.js
CHANGED
|
@@ -2,6 +2,7 @@ import { setContext, getContext, hasContext } from 'svelte';
|
|
|
2
2
|
import { toast } from 'svelte-sonner';
|
|
3
3
|
import { enhance } from '$app/forms';
|
|
4
4
|
import { goto } from '$app/navigation';
|
|
5
|
+
import { writable } from 'svelte/store';
|
|
5
6
|
const formContextKey = {};
|
|
6
7
|
export const formContext = {
|
|
7
8
|
get: () => {
|
|
@@ -12,6 +13,7 @@ export const formContext = {
|
|
|
12
13
|
};
|
|
13
14
|
export function useForm({ onSubmit, onSuccess, onResetError, onError, onFail, successUpdate = true, successReset = true, successMessage = 'Succès' } = {}) {
|
|
14
15
|
const { setError } = formContext.get();
|
|
16
|
+
const isLoading = writable(false);
|
|
15
17
|
async function resetErrors() {
|
|
16
18
|
for (const key in setError)
|
|
17
19
|
setError[key]('');
|
|
@@ -41,10 +43,12 @@ export function useForm({ onSubmit, onSuccess, onResetError, onError, onFail, su
|
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
45
|
const submit = async (event) => {
|
|
46
|
+
isLoading.set(true);
|
|
44
47
|
if (onSubmit)
|
|
45
48
|
await onSubmit(event);
|
|
46
49
|
event.submitter?.classList.add('btn-disabled');
|
|
47
50
|
return async ({ result, update, action }) => {
|
|
51
|
+
isLoading.set(false);
|
|
48
52
|
event.submitter?.classList.remove('btn-disabled');
|
|
49
53
|
if (result.type === 'error') {
|
|
50
54
|
if (onError)
|
|
@@ -86,6 +90,7 @@ export function useForm({ onSubmit, onSuccess, onResetError, onError, onFail, su
|
|
|
86
90
|
return {
|
|
87
91
|
enhance: (form) => enhance(form, submit),
|
|
88
92
|
submit,
|
|
93
|
+
isLoading,
|
|
89
94
|
resetErrors,
|
|
90
95
|
setError(key, value) {
|
|
91
96
|
if (!setError[key]) {
|