Open unlocomqx opened 3 months ago
It didn't occur to me to extract the form into a separate component 🤦 So this would work
{#each superforms as superform}
<Comp {superform} />
{/each}
Closing.
I'm reopening this issue because I encountered a problem
When I write this code
<script>
const superforms = data.my_forms.map((form) =>
superForm(form, {
dataType: 'json'
})
);
</script>
{#each superforms as superform (superform.formId)}
<ConditionItem {superform} />
{/each}
It works well but when a new form is added, then that's where I run into a problem
If I try to use $derived
const superforms = $derived(
data.condition_forms.map((form) =>
superForm(form, {
dataType: 'json'
})
)
);
I get this error
Uncaught Error: onDestroy can only be used during component initialisation.
Repro https://www.sveltelab.dev/9tdm9ul193m3tz5
A PR for this would be very nice!
Okay, I will send a PR for this
The problem is bigger than I anticipated, it'll require an overhaul of the onDestroy/cleanup handling. It'll have to wait until later. For now, using calls to superForm
within $derived
cannot be used.
Okay, it will be good to have dynamic forms in the future. I will try to find a workaround for now.
Description I tried retuning multiple superforms in an array, but I could not use it in the frontend. The only convenient way was to destructure each superform in the each tag but svelte doesn't support "declaring" stores out of the top-level of the component
If applicable, a MRE https://www.sveltelab.dev/9tdm9ul193m3tz5