[FIX] web: test broken in Firefox
This is arguably a 20 years old Firefox bug (at the very least an under-specified area of the spec where Firefox's behaviour is technically allowed under spec but not super useful or convenient): `window.getSelection()` simply doesn't work when invoked on a form field: https://bugzilla.mozilla.org/show_bug.cgi?id=85686. Getting the selection data more explicitly by looking up the focused form element, then checking *its* selection, seems to work fine and be cross-browser. Also focus() the input while at it: according to MDN > Calling element.select() will not necessarily focus the input, so it > is often used with HTMLOrForeignElement.focus. And jQuery doesn't really document whether `select()` will implicitly `focus()`, so better safe than sorry. closes odoo/odoo#69579 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
This commit is contained in:
@@ -881,6 +881,7 @@ var FieldDate = InputField.extend({
|
||||
*/
|
||||
activate: function () {
|
||||
if (this.isFocusable() && this.datewidget) {
|
||||
this.datewidget.$input.focus();
|
||||
this.datewidget.$input.select();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4314,7 +4314,7 @@ QUnit.module('basic_fields', {
|
||||
});
|
||||
|
||||
QUnit.test('field date should select its content onclick when there is one', async function (assert) {
|
||||
assert.expect(2);
|
||||
assert.expect(3);
|
||||
var done = assert.async();
|
||||
|
||||
var form = await createView({
|
||||
@@ -4332,7 +4332,10 @@ QUnit.module('basic_fields', {
|
||||
'show.datetimepicker': function () {
|
||||
assert.ok($('.bootstrap-datetimepicker-widget').is(':visible'),
|
||||
'bootstrap-datetimepicker is visible');
|
||||
assert.strictEqual(window.getSelection().toString(), "02/03/2017",
|
||||
const active = document.activeElement;
|
||||
assert.equal(active.tagName, 'INPUT', "The datepicker input should be focused");
|
||||
const sel = active.value.slice(active.selectionStart, active.selectionEnd);
|
||||
assert.strictEqual(sel, "02/03/2017",
|
||||
'The whole input of the date field should have been selected');
|
||||
done();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user