[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
This commit is contained in:
Nicolas Lempereur
2015-09-14 12:44:46 +02:00
parent 25eb2c00a9
commit f7f436ead5
+8 -2
View File
@@ -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) {