Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow customizing day cell value #2043

Merged
merged 7 commits into from
Feb 12, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion js/bootstrap-datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,8 @@
clsName = this.getClassNames(prevMonth);
clsName.push('day');

var displayDate = prevMonth.getUTCDate();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since other tickets like #2037 would like such PR, I think a more abstract name for this option should be use, like content. Do you guys agree @acrobat @vsn4ik @hebbet ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


if (this.o.beforeShowDay !== $.noop){
before = this.o.beforeShowDay(this._utc_to_local(prevMonth));
if (before === undefined)
Expand All @@ -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)
Expand All @@ -1041,7 +1045,7 @@
clsName = $.unique(clsName);
}

html.push('<td class="'+clsName.join(' ')+'"' + (tooltip ? ' title="'+tooltip+'"' : '') + (this.o.dateCells ? ' data-date="'+(prevMonth.getTime().toString())+'"' : '') + '>'+prevMonth.getUTCDate() + '</td>');
html.push('<td class="'+clsName.join(' ')+'"' + (tooltip ? ' title="'+tooltip+'"' : '') + (this.o.dateCells ? ' data-date="'+(prevMonth.getTime().toString())+'"' : '') + '>' + displayDate + '</td>');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are actually making the other views sad and envious to the monthView :)
May you add this on the other views please ?

tooltip = null;
if (weekDay === this.o.weekEnd){
html.push('</tr>');
Expand Down Expand Up @@ -1196,6 +1200,10 @@
}

if (!target.hasClass('disabled')){
// Allow clicking on elements inside a day
if (target.parent().hasClass('day'))
target = target.parent();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you allow html, you code won't work if I send <div><div></div></div>, you should change e.target by e.currentTarget, but then you should do a full test to be sure it does not break everything.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that e.currentTarget would work because bubbling/propagation are stopped at the top of the click handler.

Instead, I use .parents(), does that work?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should I guess


// Clicked on a day
if (target.hasClass('day')){
day = Number(target.text());
Expand Down