question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cant get two-way value syncing to work

See original GitHub issue

How can i send the country key through the event and get the corresponding country selected. right now it just gets overwritten to a string.

<template>
    <div>
        <multiselect
            :selected.sync="selected"
            :options="options"
            @update="updateSelected"
            :searchable="true",
            :close-on-select="true",
            :allow-empty="false",
            deselect-label="Can't remove this value"
            key="key"
            label="label"
            placeholder="Select Country">

        </multiselect>
    </div>
</template>

<script>
import Multiselect from 'vue-multiselect'
export default {
    components: { Multiselect },
    data () {
        return {
          selected: null,
          options: countries
        }
    },
    methods: {
        updateSelected (newSelected) {
          this.selected = newSelected
        //   console.log(this.key);
        }
    },
    events: {
        'changeSelected': function (selected) {
          this.selected = selected;
        }
    }
}

let countries = [
    {'key' : 'AF', 'label' : 'Afghanistan'},
    {'key' : 'AX', 'label' : 'Aland Islands'},
    {'key' : 'AL', 'label' : 'Albania'},
    {'key' : 'DZ', 'label' : 'Algeria'},
    {'key' : 'AS', 'label' : 'American Samoa'},
    {'key' : 'AD', 'label' : 'Andorra'},
    ...

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
shentaocommented, Aug 20, 2016

I guess you need to set the whole object not just the key. This is because the :selected prop expects an object it would find inside the :options prop. If there is no way to broadcast the whole object to the child, try using the find array method.

events: {
  'changeSelected' (countryKey) {
    this.selected = this.options.find(country => country.key === countryKey)
  }
}

Also if this is just a wrapper component, what about passing the selected value and countries as props and skipping the $broadcast? In Vue 2.0 $broadcast it is already deprecated as it is considered a bad design. I guess one of the reasons for this is that you have to be very careful not to use the changeSelected event in any of the parent components.

0reactions
shentaocommented, Aug 20, 2016

Happy to help! 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix Google Authenticator Codes That Have Stopped ...
All you have to do is make sure your Google Authenticator app's time is synced correctly. Launch the app, tap the menu button...
Read more >
Resolve sync issues in Mail and Calendar apps in Windows 10
Go to Start and open Mail. · At the bottom of the left navigation pane, select The Settings button · Select Manage Accounts....
Read more >
Does Zapier support two-way syncing?
No. Zapier does not support two-way syncing between apps right now. Think of Zaps like one-way workflows. In certain scenarios, you can...
Read more >
Fix common issues with 2-Step Verification - Google Support
Tip: If you requested multiple verification codes, only the newest one works. My Google Authenticator codes don't work. It may be because the...
Read more >
Secure keychain syncing - Apple Support
New devices, as they sign into iCloud, join the iCloud Keychain syncing circle in one of two ways: either by pairing with and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found