material-datetime-picker
material-datetime-picker copied to clipboard
Picker won't open with previously picked datetime
Hi there,
I am using the material datetime picker to save dates in DD-MM-YYY format. It works fine, but I can't get the picker to open with another default date as the the current date.
My attempt:
import MaterialDatePicker from "material-datetime-picker";
import moment from "moment";
const input = $el
const picker = new MaterialDatePicker(
{
default: moment(),
format: 'DD-MM-YYYY',
value: (input.value !== '' ? input.value : moment()) //attempt 1 to set input value as picker value
})
.on('submit', (val) => {
input.value = val.format("DD-MM-YYYY")
});
input.addEventListener('focus', () => {
picker.open()
//attempt 2 to set input value as picker value
picker.value = input.value
})
input.value is a date string in MM-DD-YYY format, which i'd like to open as the default picker value. Is this possible and if so; how does one achieve this?
Best regards,
Peter
In your focus handler try;
input.addEventListener('focus', () => {
picker.set(input.value);
picker.open()
})