Created
December 8, 2010 23:05
-
-
Save olistik/734092 to your computer and use it in GitHub Desktop.
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
| /* workaround for 2 bugs related to jQuery Tools Dateinput: | |
| * 1) the initial value is wrongly set | |
| * 2) "data-" attributes presents on the target input get wiped out | |
| */ | |
| $(":date[data-backend]").each(function() { | |
| var backend_attr = $(this).attr("data-backend"); | |
| var value = $(backend_attr).val(); | |
| var year = parseInt(value.substring(0, 4), 10); | |
| var month = parseInt(value.substring(4, 6), 10) - 1; | |
| var day = parseInt(value.substring(6, 8), 10); | |
| var init_date = new Date(year, month, day); | |
| $(this).dateinput({ | |
| firstDay: 1, | |
| format: "dd-mm-yyyy", | |
| selectors: true, | |
| }) | |
| .attr("data-backend", backend_attr) | |
| .change(function() { | |
| var isoDate = $(this).data("dateinput").getValue('yyyymmdd'); | |
| var backend = $(this).attr('data-backend'); | |
| $(backend).val(isoDate); | |
| }).data("dateinput").setValue(init_date); | |
| }); | |
| // the desired behavior: | |
| $(":date[data-backend]").each(function() { | |
| $(this).dateinput({ | |
| firstDay: 1, | |
| format: "dd-mm-yyyy", | |
| selectors: true | |
| }).change(function() { | |
| var isoDate = $(this).data("dateinput").getValue('yyyymmdd'); | |
| var backend = $(this).attr('data-backend'); | |
| $(backend).val(isoDate); | |
| }); | |
| }); | |
| /* | |
| the reference html: | |
| <input type="date" data-backend="#dp_start" data-value="20101101" value="2010-11-01" /> | |
| <input type="date" data-backend="#dp_end" data-value="20101130" value="20101130" /> | |
| <input id="dp_start" type="hidden" name="startDate" value="20101101" /> | |
| <input id="dp_end" type="hidden" name="endDate" value="20101130" /> | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment