[FIX] web: clear input on clicking 'Create and Edit' from many2one fields

We clear the input field when clicking 'Create and Edit' to ensure that
the field is empty if the user chooses to cancel the record creation. If
a record is indeed created, then the field value will still be updated.
This commit is contained in:
Khoi Nguyen
2017-10-09 09:00:19 +02:00
parent 5d1a1942df
commit 1bbb7d6241
2 changed files with 11 additions and 2 deletions
@@ -371,9 +371,14 @@ var FieldMany2One = AbstractField.extend({
}
// create and edit ...
if (create_enabled && !self.nodeOptions.no_create_edit) {
var createAndEditAction = function () {
// Clear the value in case the user clicks on discard
self.$('input').val('');
return self._searchCreatePopup("form", false, self._createContext(search_val));
};
values.push({
label: _t("Create and Edit..."),
action: self._searchCreatePopup.bind(self, "form", false, self._createContext(search_val)),
action: createAndEditAction,
classname: 'o_m2o_dropdown_option',
});
} else if (values.length === 0) {
@@ -1489,7 +1489,7 @@ QUnit.module('relational_fields', {
QUnit.test('pressing ENTER on a \'no_quick_create\' many2one should not trigger M2ODialog', function (assert) {
var done = assert.async();
assert.expect(1);
assert.expect(2);
var M2O_DELAY = relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY;
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = 0;
@@ -1527,6 +1527,10 @@ QUnit.module('relational_fields', {
$input.blur();
assert.strictEqual($('.modal').length, 1,
"should have one modal in body");
// Check that discarding clears $input
$('.modal .o_form_button_cancel').click();
assert.strictEqual($input.val(), '',
"the field should be empty");
form.destroy();
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = M2O_DELAY;
done();