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.

on:selected get previous selected value

See original GitHub issue

Hi, I got some problems when I use the on:selected to passing data to parent component. Here is my code snippet. When I use on:selected to execute the setBeginDate / setEndDate, I will get the previous selected date. Did I do anything wrong?

<template lang="html">
    <div>
          <datepicker v-model="beginDate" v-on:selected="setBeginDate" format="yyyy-MM-dd" input-class="datepicker-input" wrapper-class="datepicker-wrapper" :clear-button='true'></datepicker>
            <datepicker v-model="endDate" v-on:selected="setEndDate" format="yyyy-MM-dd" input-class="datepicker-input" wrapper-class="datepicker-wrapper" :clear-button='true'></datepicker>
    </div>
</template>

<script>
import Datepicker from 'vuejs-datepicker';

export default {
    data() {
        return {
            beginDate: new Date(),
            endDate: new Date(),
        };
    },
    components: {
        datepicker: Datepicker,
    },
    methods: {
        setBeginDate() {
            console.log(this.beginDate); // always get the previous selected beginDate date
            this.$parent.dateListener(this.beginDate);
        },
        setEndDate() {
            console.log(this.endDate); // always get the previous selected endDate date
            this.$parent.dateListener(null, this.endDate);
        }
    }
}
</script>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
JeanBarrierecommented, Mar 26, 2017

I had a similar problem. To fix it, I use watch property to listen on data change. Here you can do:

watch: {
  beginDate: function(val) {
    // do whatever you want with the new value
  },
  ...
}

and it would work for you.

0reactions
guptamanish07commented, Nov 9, 2020

@JeanBarriere Thanks a a lot, it did work. However, do you know what cause the on:selected problem? can you help i am facing the same problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting value of select (dropdown) before change
Lets say currently option My is selected now when I change it to stack in the onchange event (i.e. when I changed it...
Read more >
How do I get the text value of a selected option?
Select elements typically have two values that you want to access. First there's the value to be sent to the server, which is...
Read more >
Angular Basics: How To Get Value of Selected Dropdown Item
The onSelect method receives the reference variable and takes the value of the dropdown element. The code will look like this: <div class="col ......
Read more >
How do I retrieve a selected value of the select control?
Couldn't find the FAQs you're looking for? Please submit your question and answer. Platform.
Read more >
Change dropdown value OnSelect - Power Platform Community
OnSelect = UpdateContext({TimeVariable: Dropdown1.Selected.Value})` ... YouTube, and PowerApps Consulting for when you are in a bind to get this fixed ...
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