[FIX] web, barcodes: restore disableAutofocus option
This option has been removed with the new views but was used in barcode. The form renderer was also dealing with some part of the autofocus but this should only be handled by the controller. The logic is now only in the controller and a test case has been added.
This commit is contained in:
committed by
Aaron Bohy
parent
b131e9b0ef
commit
5b968ad371
@@ -171,6 +171,10 @@ FormController.include({
|
||||
candidate: this.activeBarcode[name] && this.activeBarcode[name].handle === this.handle ?
|
||||
this.activeBarcode[name].candidate : null,
|
||||
};
|
||||
|
||||
// we want to disable autofocus when activating the barcode to avoid
|
||||
// putting the scanned value in the focused field
|
||||
this.disableAutofocus = true;
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
|
||||
@@ -28,6 +28,7 @@ var FormController = BasicController.extend({
|
||||
this._super.apply(this, arguments);
|
||||
|
||||
this.actionButtons = params.actionButtons;
|
||||
this.disableAutofocus = params.disableAutofocus;
|
||||
this.footerToButtons = params.footerToButtons;
|
||||
this.defaultButtons = params.defaultButtons;
|
||||
this.hasSidebar = params.hasSidebar;
|
||||
@@ -42,7 +43,9 @@ var FormController = BasicController.extend({
|
||||
* Calls autofocus on the renderer
|
||||
*/
|
||||
autofocus: function () {
|
||||
this.renderer.autofocus();
|
||||
if (!this.disableAutofocus) {
|
||||
this.renderer.autofocus();
|
||||
}
|
||||
},
|
||||
/**
|
||||
* This method switches the form view in edit mode, with a new record.
|
||||
@@ -305,7 +308,7 @@ var FormController = BasicController.extend({
|
||||
this.set('title', title);
|
||||
this._updateButtons();
|
||||
this._updateSidebar();
|
||||
return this._super.apply(this, arguments);
|
||||
return this._super.apply(this, arguments).then(this.autofocus.bind(this));
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
|
||||
@@ -815,9 +815,6 @@ var FormRenderer = BasicRenderer.extend({
|
||||
self._addFieldTooltip(widget, $label);
|
||||
}
|
||||
});
|
||||
|
||||
// Focus the default field (in edit mode)
|
||||
self.autofocus();
|
||||
},
|
||||
/**
|
||||
* Sets id attribute of given widget to idForLabel
|
||||
|
||||
@@ -29,6 +29,7 @@ var FormView = BasicView.extend({
|
||||
this.loadParams.type = 'record';
|
||||
this.loadParams.parentID = params.parentID;
|
||||
|
||||
this.controllerParams.disableAutofocus = params.disable_autofocus;
|
||||
this.controllerParams.hasSidebar = params.sidebar;
|
||||
this.controllerParams.toolbarActions = viewInfo.toolbar;
|
||||
this.controllerParams.footerToButtons = params.footer_to_buttons;
|
||||
|
||||
@@ -4197,6 +4197,32 @@ QUnit.module('Views', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('no autofocus with disable_autofocus option [REQUIRE FOCUS]', function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form string="Partners">' +
|
||||
'<field name="int_field"/>' +
|
||||
'<field name="foo"/>' +
|
||||
'</form>',
|
||||
viewOptions: {
|
||||
disable_autofocus: true,
|
||||
},
|
||||
});
|
||||
assert.notStrictEqual(document.activeElement, form.$('input[name="int_field"]')[0],
|
||||
"int_field field should not have focus");
|
||||
|
||||
form.update({});
|
||||
|
||||
assert.notStrictEqual(document.activeElement, form.$('input[name="int_field"]')[0],
|
||||
"int_field field should not have focus");
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('open one2many form containing many2many_tags', function (assert) {
|
||||
assert.expect(4);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user