[FIX] web: escape pressed in editable list in dialog

should discard the edited row, but not close the dialog. Before
this rev., it was closing the dialog.
This commit is contained in:
Aaron Bohy
2017-09-27 12:13:58 +02:00
parent df04910d2a
commit 2d3e5711f1
3 changed files with 52 additions and 2 deletions
@@ -444,7 +444,7 @@ var AbstractField = Widget.extend({
this.trigger_up('navigation_move', {direction: 'next_line'});
break;
case $.ui.keyCode.ESCAPE:
this.trigger_up('navigation_move', {direction: 'cancel'});
this.trigger_up('navigation_move', {direction: 'cancel', originalEvent: ev});
break;
case $.ui.keyCode.UP:
ev.stopPropagation();
@@ -661,6 +661,9 @@ ListRenderer.include({
this._moveToNextLine();
break;
case 'cancel':
// stop the original event (typically an ESCAPE keydown), to
// prevent from closing the potential dialog containing this list
ev.data.originalEvent.stopPropagation();
this.trigger_up('discard_changes', {
recordID: ev.target.dataPointID,
});
@@ -3204,6 +3204,54 @@ QUnit.module('relational_fields', {
form.destroy();
});
QUnit.test('pressing escape in editable o2m list in dialog', function (assert) {
assert.expect(3);
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<group>' +
'<field name="p">' +
'<tree>' +
'<field name="display_name"/>' +
'</tree>' +
'</field>' +
'</group>' +
'</form>',
res_id: 1,
archs: {
"partner,false,form": '<form>' +
'<field name="p">' +
'<tree editable="bottom">' +
'<field name="display_name"/>' +
'</tree>' +
'</field>' +
'</form>',
},
viewOptions: {
mode: 'edit',
},
});
form.$('.o_field_x2many_list_row_add a').click();
$('.modal .o_field_x2many_list_row_add a').click();
assert.strictEqual($('.modal .o_data_row.o_selected_row').length, 1,
"there should be a row in edition in the dialog");
// trigger keydown ESCAPE in the edited row
$('.modal .o_data_cell input').trigger({type: 'keydown', which: $.ui.keyCode.ESCAPE});
assert.strictEqual($('.modal').length, 1,
"dialog should still be open");
assert.strictEqual($('.modal .o_data_row').length, 0,
"the row should have been removed");
form.destroy();
});
QUnit.test('editable o2m with onchange and required field: delete an invalid line', function (assert) {
assert.expect(5);
@@ -5586,7 +5634,6 @@ QUnit.module('relational_fields', {
form.destroy();
});
QUnit.test('editing tabbed one2many (editable=bottom)', function (assert) {
assert.expect(11);