If you (like me) want to have an action that works like enhance
but that never resets the entered values in the <form>
, I think you can use the following customEnhance
that I just wrote for this specific purpose:
custom-enhance.js
import { enhance } from '$app/forms';
export function customEnhance(form, submitFunction) {
function customSubmitFunction() {
return async (actionResult) => {
await actionResult.update({reset: false})
if(submitFunction){
await submitFunction(actionResult)
}
}
}
return enhance(form, customSubmitFunction)
}
+page.svelte
<script>
import { customEnhance } from './custom-enhance'
</script>
<form method="POST" use:customEnhance>
<!-- Does never reset form values, but does otherwise work like "enhance". -->
...
</form>
I haven't tested it much yet, so no guarantees I got the implementation right, but works good for me so far :)