mskocik / svelecte

Flexible autocomplete/select component written in Svelte,
https://svelecte.vercel.app
MIT License
471 stars 43 forks source link

Multiselect bug: option.selected attribute not set to true on initial load #220

Closed marko1010 closed 8 months ago

marko1010 commented 8 months ago

On initial page load the selected options appear correctly in the UI but inside the generated <select> element only one option has the selected attribute set to true

  <Svelecte
      multiple={true}
      collapseSelection="always"
      clearable={true}
      keepSelectionInList={true}
      searchProps={{ skipSort: true }}
      options={provinces}
      value={data.provinces}
      name="provinces[]"
  ></Svelecte>

I have to use this as a workaround when submitting form:

document.addEventListener('submit', function(event) {
    document.querySelectorAll('form select.sv-hidden-element option').forEach(x => x.selected = true)
}, true); 
mskocik commented 8 months ago

This was reported before, but due the lack of user input I wasn't sure it's still present. Related issue: #168

In general it is related to unfixed svelte bug.