vue-datetime
vue-datetime copied to clipboard
can it run off a button instead of an input field?
Sounds good, I thought three options:
- Add a simply property to draw a button instead of an input
If we want to be more customizable we can:
- Add a slot to override the input
- Or add a property
no-input
or similar and another one to set theopen
status
What do you think?
option two sounds most flexible
would be good to have a short chat about it. how can I contact you?
Just to leave this here, you can accomplish it this way:
In the template:
<button @click="openPicker">Open it!</button>
<datetime
ref="date-picker"
v-model="date" />
In Methods:
openPicker () {
this.$refs['date-picker'].$el.firstChild.click()
}
In your CSS:
.vdatetime-input {
display: none;
}
This would be a really handy feature and would un-bind the datetime popup control from the input field. There are so many cases that a datetime picker is needed without an input field. @zombeej solution/hack does not work for me, it throws an error (Uncaught TypeError: this.$refs['datepicker'].$el.firstChild.click is not a function
with the right datetime ref="datepicker"
) and there is also a problem with bootstap 4 modal, because the overlay fixed position actually fits inside the modal instead of the whole window and in cases like this one, would be nice to have the picker popup independently without an input or to bind it to another input.
EDIT
My workaround for bootstrap 4 modal is to add the datetime component outside the modal, hide the input like @zombeej does, add highther than boostrap modal z-index for both vdatetime-overlay
and vdatetime-popup
classes and call this.$refs.datepicker.open(event);
bind to focus event on an input field inside the modal. It works for me, but it would be really nice to have it working with no need of an input control.
This would be a really handy feature and would un-bind the datetime popup control from the input field. There are so many cases that a datetime picker is needed without an input field. @zombeej solution/hack does not work for me, it throws an error (
Uncaught TypeError: this.$refs['datepicker'].$el.firstChild.click is not a function
with the right datetimeref="datepicker"
) and there is also a problem with bootstap 4 modal, because the overlay fixed position actually fits inside the modal instead of the whole window and in cases like this one, would be nice to have the picker popup independently without an input or to bind it to another input.EDIT My workaround for bootstrap 4 modal is to add the datetime component outside the modal, hide the input like @zombeej does, add highther than boostrap modal z-index for both
vdatetime-overlay
andvdatetime-popup
classes and callthis.$refs.datepicker.open(event);
bind to focus event on an input field inside the modal. It works for me, but it would be really nice to have it working with no need of an input control.
This helped me a lot. Must be added to the docs.