I am trying to use bootstrap-datepicker with Vue.js Trying to create a simple datepicker component. The problem is, when I write into input, component's data is updated. But when I use datepicker gui, it doesn't work. Data is not updated. Why? What is missing exactly?
Here is my code:
I couldn't find a better way than losing focus (blur).
Here's my code:
Vue.component('picker', {
'props': ['date'],
'template': '\
<div class="form-group">\
<div class="input-group date datepicker">\
<input type="text" class="form-control" :value="this.date" v-on:focus="datepick_dialog_open" v-on:blur="select_by_lose_focus">\
<span class="input-group-addon">\
<span class="glyphicon glyphicon-calendar"></span>\
</span>\
</div>\
</div>',
'mounted': function() {
$(this.$el.firstChild).datetimepicker();
},
'methods': {
'datepick_dialog_open': function() {
this.$el.firstChild.children[1].click();
},
'select_by_lose_focus': function() {
console.log('AHOY!');
this.date = this.$el.firstChild.firstChild.value;
}
}
});
app = new Vue({
'el': '#app',
'data': {}
});
The point is, you really can't use it if your element does not lose focus. It updates the data when input loses its focus. IDK any better way.
v-on:focus
is irrelevant. It just opens the datetime picker UI when input gains focus.
The main job is done by select_by_lose_focus
.