svelecte icon indicating copy to clipboard operation
svelecte copied to clipboard

readSelection does not return whole object ?

Open FluffyDiscord opened this issue 2 years ago • 5 comments

Hi, the readSelection seems to not return the whole passed object as is stated in the docs.

I have array of categories

[
  {
    "id": 2,
    "name": "Kategorie A",
    "multipleAllowed": false,
    "children": [],
    "parts": [],
    "rootId": 1,
    "rootName": "Čalounění",
    "root": {
      "id": 1,
      "name": "Čalounění"
    }
  },
  {
    "id": 3,
    "name": "Kategorie A",
    "multipleAllowed": false,
    "children": [],
    "parts": [],
    "rootId": 1,
    "rootName": "Čalounění",
    "root": {
      "id": 1,
      "name": "Čalounění"
    }
  }
]

setup as this

  <Svelecte
        searchable={false}
        options={category.children}
        inputId="sp-cat-{category.id}"
        bind:readSelection={selectedCategory}
        bind:value={selectedCategoryId}
        on:change={handleCategorySelect}
        placeholder="Vyberte kategorii"
/>

Sometimes the read selection returns just a option like object

{
  "id": 2,
  "name": "Kategorie A"
}

instead of a whole thing

Am I missing something ?

This happens only the second time the svelecte component is initialized/updated. I did check the passed options prop and it's fine

FluffyDiscord avatar May 24 '22 15:05 FluffyDiscord

Are you using the latest version? If yes, can you setup reproducible example in REPL? It works fine for me when I am trying this.

mskocik avatar May 24 '22 16:05 mskocik

Can you at least share how your svelecte markup looks like?

On 1. 6. 2022 14:53, tom-acceleratecompliance wrote:

Hi, I'll also try to bring together a reproduction case for this. It is always occurring to one of my dropdown, and never to another, even though they seem to be effectively identical.

I have three keys in my object, |id|, |name| and |email| and ID is always dropped from |readSelection| or |value| when in |valueAsObject| mode.

mskocik avatar Jun 01 '22 14:06 mskocik

I have rewrote the logic so that I don't use readSelection at all, since I had to finish my project. This can be probably closed... The behavior is weird and hard to isolate.

FluffyDiscord avatar Jun 01 '22 16:06 FluffyDiscord

Apologies for my message @mskocik - the issue was found upstream of the component through a series of binds.

tom-asmblr avatar Jun 01 '22 23:06 tom-asmblr

@tom-acceleratecompliance thanks for clarifying your case.

Anyway I will keep this open as potential bug.

mskocik avatar Jun 02 '22 06:06 mskocik

Most probably fixed in v4, which has just been released. Re-open if you would know how to reproduce it

mskocik avatar Feb 24 '24 11:02 mskocik