[FIX] web: open domain selector's datepicker at the right position

Before this commit, and since the combination of new views + datepicker
library update, the datepicker opened at the top left of the window
when using it in a domain selector. It also could not be used at all.

This was because the current scenario occured:
1) Click on the datepicker
2) The datepicker triggers that it has changed on opening
3) The whole domain selector is rerendered
4) The datepicker computes where it should open... on basis of the
   old destroyed domain selector

As the main cause of the problem here was the (2), this commit changes
the datepicker odoo widget to only notifies that it has changed when it
has really changed.
This commit is contained in:
qsm-odoo
2017-09-21 14:51:12 +02:00
parent 5b216c03c1
commit b51b0d66c2
2 changed files with 19 additions and 4 deletions
@@ -74,9 +74,16 @@ var DateWidget = Widget.extend({
* set datetime value
*/
changeDatetime: function () {
if(this.isValid()) {
if (this.isValid()) {
var oldValue = this.getValue();
this._setValueFromUi();
this.trigger("datetime_changed");
var newValue = this.getValue();
if (!oldValue !== !newValue || oldValue && newValue && !oldValue.isSame(newValue)) {
// The condition is strangely written; this is because the
// values can be false/undefined
this.trigger("datetime_changed");
}
}
},
/**
@@ -151,7 +151,7 @@ QUnit.module('DomainSelector', {
});
QUnit.test("building a domain with a datetime", function (assert) {
assert.expect(1);
assert.expect(2);
var $target = $("#qunit-fixture");
@@ -163,8 +163,16 @@ QUnit.module('DomainSelector', {
domainSelector.appendTo($target);
// Check that there is a datepicker to choose the date
assert.strictEqual(domainSelector.$(".o_datepicker:visible").length, 1,
var $datepicker = domainSelector.$(".o_datepicker:visible");
assert.strictEqual($datepicker.length, 1,
"there should be a datepicker");
var val = $datepicker.find('input').focus().click().val();
$('.bootstrap-datetimepicker-widget :not(.today)[data-action="selectDay"]').click();
assert.notEqual(domainSelector.$(".o_datepicker:visible input").val(), val,
"datepicker value should have changed");
domainSelector.destroy();
});
});
});