Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Picker won't open with previously picked datetime #147

Open
petertenhoor opened this issue Aug 16, 2017 · 1 comment
Open

Picker won't open with previously picked datetime #147

petertenhoor opened this issue Aug 16, 2017 · 1 comment

Comments

@petertenhoor
Copy link

petertenhoor commented Aug 16, 2017

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

@Jivings
Copy link
Contributor

Jivings commented Sep 4, 2017

In your focus handler try;

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants