Skip to content

Adds MinMonth and MaxMonth options#21

Merged
KidSysco merged 19 commits into
KidSysco:masterfrom
benjamin-albert:master
Oct 19, 2015
Merged

Adds MinMonth and MaxMonth options#21
KidSysco merged 19 commits into
KidSysco:masterfrom
benjamin-albert:master

Conversation

@benjamin-albert
Copy link
Copy Markdown
Collaborator

If you go to the jQuery UI Download Builder and switch everything off (except for Core) you'll notice Datepicker doesn't depend on anything (including Button, Position and the Widget factory!).

This means being consistent with Datepicker isn't easy and requires some research and innovation.

After doing some research I've decided to split the three main things (this is one of them) I want to add to this plugin into multiple pull requests.

According to #11 and #5 (and a request form the systems analyst at my company) this is the most requested feature, and believe it our not I found it easier to implement this consistently with Datepicker than highlighting the current and selected month (coming up in it's own pull request).

The MinMonth and MaxMonth options are the twin brothers of the minDate and maxDate options.

In fact I've basically copied and pasted there documentation, replaced date with month and slightly modified the examples.

Take a look at the updated fiddle.
If you have better ideas for the new demo feel free to update it.

These options restrict the user to choosing a month within a given interval by disabling the irrelevant month, year, next and previous button.

Please refer to the documentation to see the different types you can pass into these options (if you've used the minDate or maxDate options in Datepicker you already know what you can pass to these options).

I purposely didn't write support for changing the Min/Max month while the menu is opened manly because I'm curious to see what neat use cases people will have for this.

Datepicker allows specifying dates as periods (+1y -3m) but unfortunately there implementation for this is buried deep within the private _determineDate() method which depends on a Datepicker instance.

So I came up with a neat trick for parsing those periods which wraps the supported tokens (currently m and y) in JSON syntax and then passes the JSON string to JSON.parse(); resulting in an object where the keys are value and vise versa.

After creating a reversed object (one who's keys are the values) I add the number of months and years specified in the object to today's date.

If the user passes in an invalid string JSON.parse(); will throw an error and I will show an alert(); error message.

This method is probably shorter than the real parser Datepicker has but it's probably not as efficient as there method.

@KidSysco
Copy link
Copy Markdown
Owner

Wow this is some really great work! Well done again Benjamin!

KidSysco added a commit that referenced this pull request Oct 19, 2015
Adds MinMonth and MaxMonth options
@KidSysco KidSysco merged commit af4ed0b into KidSysco:master Oct 19, 2015
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