material-datetime-picker icon indicating copy to clipboard operation
material-datetime-picker copied to clipboard

Picker won't open with previously picked datetime

Open petertenhoor opened this issue 7 years ago • 1 comments

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

petertenhoor avatar Aug 16 '17 09:08 petertenhoor

In your focus handler try;

input.addEventListener('focus', () => {
  picker.set(input.value);
  picker.open()
})

Jivings avatar Sep 04 '17 12:09 Jivings