Skip to content
This repository has been archived by the owner on Oct 31, 2021. It is now read-only.

multiple select : v-model init value not working #4

Open
bosquig opened this issue May 27, 2021 · 8 comments
Open

multiple select : v-model init value not working #4

bosquig opened this issue May 27, 2021 · 8 comments

Comments

@bosquig
Copy link

bosquig commented May 27, 2021

Hi,

If multiple = true, the v-model value can not be initialized with a value other than null in setup/data function. For example:

<template>
  <treeselect v-model="value" multiple :options="options" />
</template>
<script>
export default {
  data() {
    return {
        value: ['b'],
        options: [ {
          id: 'a',
          label: 'a',
          children: [ {
            id: 'aa',
            label: 'aa',
          }, {
            id: 'ab',
            label: 'ab',
          } ],
        }, {
          id: 'b',
          label: 'b',
        }, {
          id: 'c',
          label: 'c',
        } ],
      }
  }
}
</script>

does not work and throws the following error :
Uncaught (in promise) TypeError: Cannot read property 'id' of undefined
at Proxy.isSelected (vue3-treeselect.common.js:5559)

Checking for null in the isSelected function seems to be enough to fix this :

    isSelected: function isSelected(node) {
      // whether a node is selected (single-select mode) or fully-checked (multi-select mode)
      return node && this.forest.selectedNodeMap[node.id] === true;
    },

Can you fix it please ?

Thanks in advance.

@jamols09
Copy link

Is it fixed?

@apudiu
Copy link

apudiu commented Oct 25, 2021

Having same issue @bosquig, it fails when we prepopulate values in multiple mode

@bosquig
Copy link
Author

bosquig commented Oct 25, 2021

Having same issue @bosquig, it fails when we prepopulate values in multiple mode

Hi @apudiu , I've forked the repo with the fix I mentionned if you want :

npm install @bosquig/vue3-treeselect -S

@apudiu
Copy link

apudiu commented Oct 25, 2021

Having same issue @bosquig, it fails when we prepopulate values in multiple mode

Hi @apudiu , I've forked the repo with the fix I mentionned if you want :

npm install @bosquig/vue3-treeselect -S

Thank you very much, You saved the day.
Can you please submit a PR on the base repo? becoz finding it is easy.

@bosquig
Copy link
Author

bosquig commented Oct 25, 2021

Well the maintainer doesn't seem to respond whatsoever...

@jamols09
Copy link

@bosquig it wouldn't work with vite for now ?

@bosquig
Copy link
Author

bosquig commented Oct 30, 2021

@jamols09 It wouldn't work with vue 3. I don't think vite has to do with it. My forked repo with the fix works with vue 3 and vite though.

@apudiu
Copy link

apudiu commented Oct 31, 2021

@bosquig console warning still exists, can you please fix this?
I also found a bug where changing the value programmatically (like changing with setTimeout) doesn't change the label.
can you please fix this issue? BTW I really thank you for the effort you've give into this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants