chrisdavies / tiny-date-picker

A small, modern, dependency-free date picker
https://chrisdavies.github.io/tiny-date-picker/
415 stars 88 forks source link

Configuring hilightedDate & selectedDate... #122

Open ghost opened 3 years ago

ghost commented 3 years ago

Hi everyone,

Tried with no luck to set a date in the plugin. Tried only with 'selectedDate' or 'hilightedDate' too. Also tested to set the dates in this format (YYYY-MM-DD), no luck either. Is somebody have the solution or it's a bug? It'a always set to now().

IE: min/max working like a charm at least...

Regards,

TinyDatePicker('.is-below', { mode: 'dp-below', min: '2020/01/01', max: '2021/01/01', dayOffset: 0, selectedDate: '2020/10/23', hilightedDate: '2020/10/23', format(date) { return date.toLocaleDateString('en'); }, });

bornova commented 3 years ago

Hi @superdeeid, You can set the date using the setState method:

dp.setState({
    selectedDate: new Date('10/23/2020')
});

As far as the hilightedDate goes, there is already an open issue (#86) which looks like was never addressed. However, if you want to highlight a specific date every time the date picker is displayed when input has no value, one workaround would be to use the parse function to assign the date you want:

var dp = TinyDatePicker(document.querySelector('input'), {
    parse(str) {
        var date = new Date(str);
        return isNaN(date) ? new Date('10/26/2017') : date;
    }
});