Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This monthpicker requires my monthpicker.js and monthpicker.css available here: https://pastebin.com/u/Ultroman
- // If you want to see the instructions, go to this StackOverflow post: https://stackoverflow.com/a/26011321/1289974
- // The value retrieved from this monthpicker, is always the LAST day of the selected month.
- // Starts at the current month. Ranges from 100 years in the past to 10 years into the future.
- $('#end').monthpicker({
- dateFormat: 'MM yy',
- changeMonth: true,
- changeYear: true,
- showMonthAfterYear: true,
- showAnim: "drop",
- constrainInput: true,
- yearRange: "-100Y:+10Y",
- minDate: new Date(new Date().getFullYear() - 100, new Date().getMonth() + 1, 0),
- maxDate: new Date((new Date().getFullYear() + 10), new Date().getMonth() + 1, 0),
- defaultDate: new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0),
- onClose: function (dateText, inst) {
- var date = new Date(inst.selectedYear, inst.selectedMonth + 1, 0);
- $(this).monthpicker('option', 'defaultDate', date);
- $(this).monthpicker('setDate', date);
- },
- beforeShow: function (input, inst) {
- if ($(this).monthpicker("getDate") !== null) {
- // Making sure that the date set is the last of the month.
- var date = new Date(inst.selectedYear, inst.selectedMonth + 1, 0);
- if($(this).monthpicker("getDate").getDate() !== date){
- $(this).monthpicker('option', 'defaultDate', date);
- $(this).monthpicker('setDate', date);
- }
- } else {
- // If the date is null, we reset it to the defaultDate. Make sure that the defaultDate is always set to the last of the month!
- $(this).monthpicker('setDate', $(this).monthpicker('option', 'defaultDate'));
- }
- },
- onChangeMonthYear: function (year, month, inst) {
- $(this).val($.monthpicker.formatDate($(this).monthpicker('option', 'dateFormat'), new Date(year, month, 0)));
- }
- })
- //.after( // this makes a link labeled "clear" appear to the right of the input-field, which clears the text in it
- // $("<a href='javascript: void(0);'>clear</a>").click(function() {
- // $(this).prev().val('');
- // })
- //)
- ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement