From e1dfbbd32d524609df5d2c12bf4f76dedbd351a2 Mon Sep 17 00:00:00 2001 From: Chris Hynes Date: Sun, 23 Oct 2016 19:03:58 -0700 Subject: [PATCH] Allow customizing day cell value --- docs/options.rst | 1 + js/bootstrap-datepicker.js | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/options.rst b/docs/options.rst index c8380a2..68aee82 100644 --- a/docs/options.rst +++ b/docs/options.rst @@ -31,6 +31,7 @@ A function that takes a date as a parameter and returns one of the following val * ``enabled``: same as the Boolean value above * ``classes``: same as the String value above * ``tooltip``: a tooltip to apply to this date, via the ``title`` HTML attribute + * ``displayDate``: the value to display in the day cell, rather than the just the day of month beforeShowMonth diff --git a/js/bootstrap-datepicker.js b/js/bootstrap-datepicker.js index 37741bd..73fbbdb 100644 --- a/js/bootstrap-datepicker.js +++ b/js/bootstrap-datepicker.js @@ -1017,6 +1017,8 @@ clsName = this.getClassNames(prevMonth); clsName.push('day'); + var displayDate = prevMonth.getUTCDate(); + if (this.o.beforeShowDay !== $.noop){ before = this.o.beforeShowDay(this._utc_to_local(prevMonth)); if (before === undefined) @@ -1031,6 +1033,8 @@ clsName = clsName.concat(before.classes.split(/\s+/)); if (before.tooltip) tooltip = before.tooltip; + if (before.displayDate) + displayDate = before.displayDate; } //Check if uniqueSort exists (supported by jquery >=1.12 and >=2.2) @@ -1041,7 +1045,7 @@ clsName = $.unique(clsName); } - html.push(''+prevMonth.getUTCDate() + ''); + html.push('' + displayDate + ''); tooltip = null; if (weekDay === this.o.weekEnd){ html.push(''); @@ -1196,6 +1200,10 @@ } if (!target.hasClass('disabled')){ + // Allow clicking on elements inside a day + if (target.parent().hasClass('day')) + target = target.parent(); + // Clicked on a day if (target.hasClass('day')){ day = Number(target.text());