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

Introduce datepicker API (open, close, openYears, onSelectMonth, onOpen...) #34

Closed
wants to merge 2 commits into from

Conversation

alcalyn
Copy link
Contributor

@alcalyn alcalyn commented May 10, 2017

Introduces methods to handle a datepicker instance.

Example to help to fill our birthdate:

var dp = TinyDatePicker(document.querySelector('.modal-txt'));

dp.onOpen(function () {
    if (dp.isEmpty()) {
        dp.openYears();
    }
});

dp.onSelectYear(function () {
    dp.openMonths();
});

Api methods:

// Handle datepicker
dp.isEmpty();
dp.open();
dp.close();
dp.updateDate(date);
dp.openYears();
dp.openMonths();

// Events
dp.onOpen(callback);
dp.onSelectYear(callback);
dp.onSelectMonth(callback);

@chrisdavies
Copy link
Owner

Hey, thanks! I like the idea of adding extensibility points like this. I'm going to flesh it out with tests before merging it.

@chrisdavies
Copy link
Owner

I ended up taking your changes and tweaking them a bit. I'm passing the event handlers in via opts instead of adding a light-weight eventing system to the date picker. An eventing system is something we may add later, but it probably needs a mechanism for add and remove, and possibly other more robust things that I don't want to think about at the moment!

I updated the docs. But here is how your previous example would work.

    TinyDatePicker(document.querySelector('.txt-top-right'), {
        onOpen: function(dp) {
          if (dp.value === '') {
            dp.openYears();
          }
        },

        onSelectYear: function (dp) {
          dp.openMonths();
        }
      });

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

Successfully merging this pull request may close these issues.

2 participants