rob-balfre / svelte-select

Svelte Select. A select component for Svelte
https://svelte-select-examples.vercel.app
Other
1.25k stars 175 forks source link

Access to multiselect value from the HTML input #540

Closed EskelCz closed 1 year ago

EskelCz commented 1 year ago

Please would it be possible to expose the current list of selected values of a multiselect, from the HTML element? With a single select it works fine.

 Reproduction:

  1. On the example page https://svelte-select-examples.vercel.app/examples/props/multiple
  2. Select multiple values
  3. Run document.getElementsByTagName('input')[0].value in console.
  4. It returns an empty string. :(

I could really use a string of comma separated values, for automated Cypress testing. Thanks for your consideration.

rob-balfre commented 1 year ago

@EskelCz this should do the trick hopefully?

document.querySelector('.svelte-select input[type=hidden]').value

Screenshot 2023-02-05 at 12 14 08 pm
EskelCz commented 1 year ago

@rob-balfre I somehow missed the hidden input, sorry. I can use that, sure. :) Thanks

EskelCz commented 1 year ago

@rob-balfre But I must say it would be nicer to have the behavior unified, for the sake of consistency and simplicity of use. The ID set on svelte-select is passed down onto the visible input, which makes it for a natural direct selector.

rob-balfre commented 1 year ago

@EskelCz it is. The input you were targeting is the filter input. It loses its value after selection

Screenshot 2023-02-05 at 12 54 02 pm