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

Configuring hilightedDate & selectedDate... #122

Open
ghost opened this issue Oct 21, 2020 · 1 comment
Open

Configuring hilightedDate & selectedDate... #122

ghost opened this issue Oct 21, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented Oct 21, 2020

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
Copy link

bornova commented Nov 4, 2020

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;
    }
});

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

1 participant