Closed karmaral closed 2 years ago
@karmaral honestly can't even remember why we added those hidden fields TBH.
What are you using them for?
I'm using them in a form, to send data, like I'd use a default select. I gather the hidden input is just there to act as an equivalent. In Select.svelte, lines 970:990
{#if !isMulti || (isMulti && !showMultiSelect)}
<input
name={inputAttributes.name}
type="hidden"
value={value ? getSelectionLabel(value) : null} /> // this
{/if}
{#if isMulti && showMultiSelect}
{#each value as item}
<input
name={inputAttributes.name}
type="hidden"
value={item ? getSelectionLabel(item) : null} /> // this
{/each}
{/if}
If I change them to be like
value={value ? value[optionIdentifier] : null} />
I get the exact same behaviour as if I were using a regular select. I'd say this is the way it should be. I don't see why you would pass the label as the value otherwise.
If you want I could make a PR?
All good, I'll add the change to the next v5 beta as its 'technically' a breaking change.
Fixed in v5
I'm a bit baffled, but shouldn't the hidden input for the selected option not use the label as the value? In the code it seems to be getting populated with getSelectionLabel, which returns the label.
Is this correct and I'm not using it properly?