kyolun / jq-monthpicker

Automatically exported from code.google.com/p/jq-monthpicker
0 stars 0 forks source link

Patch -- Rewritten non-hijack + improvements #3

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
NOTE: This code is only tested against a few specific criteria that I needed. 
It may or may not support every situation in which the original code works. It 
can almost certainly be written more cleanly but I've wasted enough time on it 
for now.

The attached file is a nearly complete rewrite. It no longer "hijacks" the 
jQuery UI datepicker object. Instead, it introduces three additional settings 
variables. All three are optional:

monthOnly: [true, false],
showClose: [true, false],
showClear: [true, false]

"monthOnly" activates the month picker. "showClose" allows you to remove the 
"Close" button when "showButtonPanel" is enabled. "showClear" allows you to add 
a "Clear" button to the button panel (which affects the target input and closes 
the date picker).

In order to show a month picker, show the button panel, hide the close button, 
and allow the user to clear the date input box, here is a setup example:

$(document).ready(function() {
    $("[name^=expiration]").datepicker({
        showButtonPanel: true,
        monthOnly: true,
        showClose: false,
        showClear: true,

        dateFormat: "MM yy"
        defaultDate: "'.date('F y').'"
    });
});

To use the datepicker object regularly (even with this version of 
jq-monthpicker loaded), use the normal options:

$(document).ready(function() {
    $("[name^=expiration]").datepicker({
        showButtonPanel: true,
        monthOnly: true,
        showClose: false,
        showClear: true,

        dateFormat: "MM dd, yy"
        defaultDate: "'.date('F d, y').'"
    });
});

Bonus patches:

* Included the patch from Issue #1, which makes dateMin and dateMax optional 
when using jq-monthpicker.
* Included a trivial hack that allows the datepicker object to "remember" the 
current date when the day is not included in the target input (ie. it will 
pretend internally that dateFormat is "MM yy d" when you are only displaying 
"MM yy").

PS. There are several individuals who have expressed an interest in using a 
month picker on the same page as a date picker. I have not tested my changes 
for that capability but they are definitely a step in the right direction. Feel 
free to hack and recontribute.

Original issue reported on code.google.com by larg...@gmail.com on 11 Jul 2011 at 10:51

Attachments:

GoogleCodeExporter commented 8 years ago
Doh. copy+paste error. To use the datepicker normally, try this:

$(document).ready(function() {
    $("[name^=expiration]").datepicker({
        dateFormat: "MM dd, yy",
        defaultDate: "'.date('F d, y').'"
    });
});

Original comment by larg...@gmail.com on 11 Jul 2011 at 10:54