Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save borgstrom/5123122 to your computer and use it in GitHub Desktop.
Save borgstrom/5123122 to your computer and use it in GitHub Desktop.
Patch to the bootstrap datepicker (http://www.eyecon.ro/bootstrap-datepicker/) to allow a new option: setOnHide It defaults to true, but if set to false then the input field will not get a value simply from clicking off of it without actually selecting a date. We have text boxes that need to show a date picker but are optional so we don't want t…
--- js/bootstrap-datepicker.js.orig 2013-03-09 00:59:04.000000000 -0500
+++ js/bootstrap-datepicker.js 2013-03-09 01:23:06.000000000 -0500
@@ -77,6 +77,7 @@
this.startViewMode = this.viewMode;
this.weekStart = options.weekStart||this.element.data('date-weekstart')||0;
this.weekEnd = this.weekStart === 0 ? 6 : this.weekStart - 1;
+ this.setOnHide = options.setOnHide === false ? false : true;
this.fillDow();
this.fillMonths();
this.update();
@@ -112,7 +113,9 @@
if (!this.isInput) {
$(document).off('mousedown', this.hide);
}
- this.set();
+ if (this.setOnHide) {
+ this.set();
+ }
this.element.trigger({
type: 'hide',
date: this.date
@@ -155,8 +158,10 @@
typeof newDate === 'string' ? newDate : (this.isInput ? this.element.prop('value') : this.element.data('date')),
this.format
);
- this.viewDate = new Date(this.date.getFullYear(), this.date.getMonth(), 1, 0, 0, 0, 0);
- this.fill();
+ if (typeof this.date !== 'undefined') {
+ this.viewDate = new Date(this.date.getFullYear(), this.date.getMonth(), 1, 0, 0, 0, 0);
+ this.fill();
+ }
},
fillDow: function(){
@@ -376,6 +381,9 @@
return {separator: separator, parts: parts};
},
parseDate: function(date, format) {
+ if (typeof date === 'undefined') {
+ return;
+ }
var parts = date.split(format.separator),
date = new Date(),
val;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment