You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using Svelte to conditionally hide and insert form elements (using their #if directive). When doing this, serializing the form appends a value to the key in the serialized object, creating an array instead. This seems to be somewhat intended behaviour.
This results in an object with name/value pairs that map to each form control. If more than one form control shares the same name, the values will be passed as an array, e.g. { name: ['value1', 'value2'] }.
Since I'm not actively creating a new element but instead re-creating the same one, I would love an option to allow overwriting the value in the serialized object instead of creating an array (maybe on a per-key basis)?
One workaround is to visually hide the element using display: none. I made a pen to illustrate the difference: https://codepen.io/leonbeon/pen/MWxoLMm. As you can see, the value for test3 is replaced with an array when re-adding the DOM element.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm using Svelte to conditionally hide and insert form elements (using their
#if
directive). When doing this, serializing the form appends a value to the key in the serialized object, creating an array instead. This seems to be somewhat intended behaviour.Quoting the docs:
Since I'm not actively creating a new element but instead re-creating the same one, I would love an option to allow overwriting the value in the serialized object instead of creating an array (maybe on a per-key basis)?
One workaround is to visually hide the element using
display: none
. I made a pen to illustrate the difference: https://codepen.io/leonbeon/pen/MWxoLMm. As you can see, the value fortest3
is replaced with an array when re-adding the DOM element.Beta Was this translation helpful? Give feedback.
All reactions