Learner
Learner

Reputation: 81

Not able to re-populate back vue2-daterange picker value

Hi i do have existing values to be populated back for datarange picker

for single daterange picker it is working for multi it is not working

here is what i have tried

Question: range is not working and even format DD-MM-YYYY is not working

Vue.use(DatePicker.default); // don't worry about this, it's just for the demo
new Vue({
  el: '#app',
   data () {
    return {
      date1:['10-07-2021'],
      date2:['10-07-2021','18-07-2021'],
    }
  }
})
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/build.min.js"></script>
<script src="https://momentjs.com/downloads/moment.js"></script>

<div id="app">
 <date-picker v-model="date1" lang="en" format="DD-MM-YYYY"></date-picker>
  <date-picker v-model="date2" :range="Boolean(true)" format="DD-MM-YYYY" lang="en" ></date-picker>
</div>

Please help me thanks in advance!!!

Upvotes: 0

Views: 379

Answers (1)

pwlam09
pwlam09

Reputation: 96

The date picker takes standard javascript Date format. So the date has to be converted to a compatible format first e.g. YYYY-MM-DD or MM/DD/YYYY. For more information, you can refer to https://www.w3schools.com/js/js_date_formats.asp

Vue.use(DatePicker.default); // don't worry about this, it's just for the demo
new Vue({
  el: '#app',
  data() {
    return {
      date1: ['07-10-2021'],
      date2: ['07-10-2021', '07-18-2021']
    }
  }
})
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/build.min.js"></script>
<script src="https://momentjs.com/downloads/moment.js"></script>

<div id="app">
  <date-picker v-model="date1" lang="en" format="DD-MM-YYYY"></date-picker>
  <date-picker v-model="date2" :range="Boolean(true)" format="DD-MM-YYYY" lang="en"></date-picker>
</div>

Upvotes: 1

Related Questions