Adds MinMonth and MaxMonth options#21
Merged
Merged
Conversation
code to use them
Fixed typo _opendInstance renamed to _openedInstance
this method if the user passes in an options hash
or input field values is out of bounds
fixes failing unit tests
if the Min/MaxMonth was specified as a number
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
MinMonthandMaxMonthoptions 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 analert();error message.This method is probably shorter than the real parser Datepicker has but it's probably not as efficient as there method.