From 1d38515ef82dda5933e9bf7d394725a0d1fccecc Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 17 Jan 2015 14:46:47 +0100 Subject: [PATCH] Added clear method, fixes #857 --- js/bootstrap-datepicker.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/js/bootstrap-datepicker.js b/js/bootstrap-datepicker.js index 8b521795c..e083080fa 100644 --- a/js/bootstrap-datepicker.js +++ b/js/bootstrap-datepicker.js @@ -512,6 +512,25 @@ } }, + clearDates: function(){ + var element; + if (this.isInput) { + element = this.element; + } else if (this.component) { + element = this.element.find('input'); + } + + if (element) { + element.val('').change(); + } + + this.update(); + this._trigger('changeDate'); + + if (this.o.autoclose) { + this.hide(); + } + }, setDates: function(){ var args = $.isArray(arguments[0]) ? arguments[0] : arguments; this.update.apply(this, args); @@ -1024,17 +1043,7 @@ this._setDate(date, which); break; case 'clear': - var element; - if (this.isInput) - element = this.element; - else if (this.component) - element = this.element.find('input'); - if (element) - element.val("").change(); - this.update(); - this._trigger('changeDate'); - if (this.o.autoclose) - this.hide(); + this.clearDates(); break; } break;