Skip to content

Instantly share code, notes, and snippets.

@jamesperrin
Last active May 24, 2021 21:18
Show Gist options
  • Save jamesperrin/8de333d728646127ff87fca1be7fec2b to your computer and use it in GitHub Desktop.
Save jamesperrin/8de333d728646127ff87fca1be7fec2b to your computer and use it in GitHub Desktop.
/*
* jQuery plugin that converts value to date
* @requires https://jqueryui.com/
* @param {Node} True or False to Disable element
* @return {String} Formatted date
*/
(function ($) {
$.fn.getDateMmddyy = function () {
if (this.val() == null) {
return null;
}
return $.datepicker.parseDate("yyyy/mm/dd", this.val());
}
}(jQuery));
/*
* jQuery plugin that converts value to date
* @requires https://jqueryui.com/
* @param {Node} The element
* @return {String} Formatted date and time
*/
(function ($) {
$.fn.getDateTimeMmddyy = function () {
if (this.val() == null) {
return null;
}
return $.datepicker.parseDate("yyyy/mm/dd", this.val());
}
}(jQuery));
$(function () {
// jQuery UI DatePicker
$("body").delegate(".jqui--datetime", "focus", function () {
if (!$(this).hasClass("hasDatepicker")) {
const minDate = getDateMmddyy($(this).data("val-rangedate-min"));
const maxDate = getDateMmddyy($(this).data("val-rangedate-max"));
$(this).datepicker({
showButtonPanel: true,
dateFormat: "mm/dd/yy",
minDate: minDate,
maxDate: maxDate,
numberOfMonths: 1
});
}
$.datepicker._gotoToday = function (id) {
$(id).datepicker('setDate', new Date(maxDate)).datepicker('hide').blur();
};
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment