sveltekit-superforms
Advanced tools
Comparing version 0.5.16 to 0.5.17
@@ -69,10 +69,18 @@ import { enhance, applyAction } from '$app/forms'; | ||
} | ||
const initialForm = form; | ||
// Make a deep copy of the original, in case of reset | ||
const initialForm = { | ||
...form, | ||
data: { ...form.data }, | ||
errors: { ...form.errors }, | ||
constraints: { ...form.constraints } | ||
}; | ||
// Stores for the properties of Validation<T> | ||
const Valid = writable(initialForm.valid); | ||
const Errors = writable(initialForm.errors); | ||
const Data = writable(initialForm.data); | ||
const Empty = writable(initialForm.empty); | ||
const Message = writable(initialForm.message); | ||
const Constraints = writable(initialForm.constraints); | ||
// Cannot be initialForm here, otherwise the initial | ||
// values will be overwritten. | ||
const Valid = writable(form.valid); | ||
const Errors = writable(form.errors); | ||
const Data = writable(form.data); | ||
const Empty = writable(form.empty); | ||
const Message = writable(form.message); | ||
const Constraints = writable(form.constraints); | ||
// Timers | ||
@@ -106,3 +114,3 @@ const Submitting = writable(false); | ||
} | ||
function rebind(form, untaint) { | ||
function rebind(form, untaint, message) { | ||
if (untaint) { | ||
@@ -112,3 +120,3 @@ savedForm = { ...form.data }; | ||
Data.set(form.data); | ||
Message.set(form.message); | ||
Message.set(message ?? form.message); | ||
Empty.set(form.empty); | ||
@@ -131,6 +139,6 @@ Valid.set(form.valid); | ||
if (form.valid && options.resetForm) { | ||
_resetForm(); | ||
_resetForm(form.message); | ||
} | ||
else { | ||
rebind(form, untaint); | ||
rebind(form, untaint, null); | ||
} | ||
@@ -142,4 +150,4 @@ // Do not await on onUpdated, since we're already finished with the request | ||
} | ||
function _resetForm() { | ||
rebind(initialForm, true); | ||
function _resetForm(message) { | ||
rebind(initialForm, true, message); | ||
} | ||
@@ -154,3 +162,3 @@ const Data_update = async (result, untaint) => { | ||
if (options.resetForm) | ||
_resetForm(); | ||
_resetForm(null); | ||
return; | ||
@@ -229,3 +237,3 @@ } | ||
// It's a page reload, so don't trigger any events, just update the data. | ||
rebind(p.data.form, true); | ||
rebind(p.data.form, true, null); | ||
} | ||
@@ -263,3 +271,3 @@ }); | ||
update: Data_update, | ||
reset: _resetForm | ||
reset: () => _resetForm(null) | ||
}; | ||
@@ -266,0 +274,0 @@ } |
{ | ||
"name": "sveltekit-superforms", | ||
"version": "0.5.16", | ||
"version": "0.5.17", | ||
"author": "Andreas Söderlund <ciscoheat@gmail.com> (https://blog.encodeart.dev)", | ||
@@ -64,3 +64,3 @@ "description": "Supercharge your SvelteKit forms with this powerhouse of a library!", | ||
"@sveltejs/adapter-auto": "^2.0.0", | ||
"@sveltejs/kit": "^1.8.8", | ||
"@sveltejs/kit": "^1.10.0", | ||
"@sveltejs/package": "^2.0.2", | ||
@@ -75,3 +75,3 @@ "@typescript-eslint/eslint-plugin": "^5.54.0", | ||
"prettier-plugin-svelte": "^2.9.0", | ||
"publint": "^0.1.9", | ||
"publint": "^0.1.10", | ||
"sass": "^1.58.3", | ||
@@ -86,3 +86,3 @@ "slugify": "^1.6.5", | ||
"vitest": "^0.25.8", | ||
"zod": "^3.20.6" | ||
"zod": "^3.21.0" | ||
}, | ||
@@ -89,0 +89,0 @@ "type": "module", |
82957
1349