From f7f436ead568d9f948dd48293fcd15182dfe8770 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Fri, 11 Sep 2015 16:07:17 +0200 Subject: [PATCH] [FIX] web: date widget, set date when shown In 36146b3f setting the date of the datetimepicker was done when it was opened, but only for widget datetime. Thus we could get an issue for a widget date when we wanted to use it to select two same date. e.g if we select 23 september for a date, it works. if we then use the widget on another date, 23 september is selected and it will not trigger a value change if we leave this value. This fix adds the date setting when opening the date widget, and also prevents the bootstrap datetimepicker feature* of closing the widget when setting the value of the date-only picker. closes #8506 opw-648619 * this feature is explained in the following issue: https://github.com/Eonasdan/bootstrap-datetimepicker/issues/603 --- addons/web/static/src/js/view_form.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 0d7df4688c8..929db311e30 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2759,12 +2759,18 @@ instance.web.DateTimeWidget = instance.web.Widget.extend({ set_datetime_default: function(){ //when opening datetimepicker the date and time by default should be the one from //the input field if any or the current day otherwise - if (this.type_of_date === 'datetime') { + if (_.contains(['datetime', 'date'], this.type_of_date)) { value = moment().second(0); if (this.$input.val().length !== 0 && this.is_valid_()){ var value = this.$input.val(); } - this.$('.oe_datepicker_main').data('DateTimePicker').setValue(value); + var dt = this.$('.oe_datepicker_main').data('DateTimePicker'); + // temporarily set pickTime to true to bypass datetimepicker hiding on setValue + // see https://github.com/Eonasdan/bootstrap-datetimepicker/issues/603 + var saved_picktime = dt.options.pickTime; + dt.options.pickTime = true; + dt.setValue(value); + dt.options.pickTime = saved_picktime; } }, change_datetime: function(e) {