[FIX] web: autofocus
Support autofocus on notebook pages: ``` <page autofocus="autofocus"> ``` This was supported before the web client refactoring. opw-801259
This commit is contained in:
committed by
Nicolas Martinelli
parent
309b6b8e5a
commit
411a9fa326
@@ -693,6 +693,7 @@ var FormRenderer = BasicRenderer.extend({
|
||||
var self = this;
|
||||
var $headers = $('<ul class="nav nav-tabs">');
|
||||
var $pages = $('<div class="tab-content nav nav-tabs">');
|
||||
var autofocusTab = -1;
|
||||
// renderedTabs is used to aggregate the generated $headers and $pages
|
||||
// alongside their node, so that their modifiers can be registered once
|
||||
// all tabs have been rendered, to ensure that the first visible tab
|
||||
@@ -701,9 +702,8 @@ var FormRenderer = BasicRenderer.extend({
|
||||
var pageID = _.uniqueId('notebook_page_');
|
||||
var $header = self._renderTabHeader(child, pageID);
|
||||
var $page = self._renderTabPage(child, pageID);
|
||||
if (index === 0) {
|
||||
$header.addClass('active');
|
||||
$page.addClass('active');
|
||||
if (autofocusTab === -1 && child.attrs.autofocus === 'autofocus') {
|
||||
autofocusTab = index;
|
||||
}
|
||||
self._handleAttributes($header, child);
|
||||
$headers.append($header);
|
||||
@@ -714,6 +714,11 @@ var FormRenderer = BasicRenderer.extend({
|
||||
node: child,
|
||||
};
|
||||
});
|
||||
if (renderedTabs.length) {
|
||||
var tabToFocus = renderedTabs[Math.max(0, autofocusTab)];
|
||||
tabToFocus.$header.addClass('active');
|
||||
tabToFocus.$page.addClass('active');
|
||||
}
|
||||
// register the modifiers for each tab
|
||||
_.each(renderedTabs, function (tab) {
|
||||
self._registerModifiers(tab.node, self.state, tab.$header, {
|
||||
|
||||
@@ -483,6 +483,37 @@ QUnit.module('Views', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('autofocus on second notebook page', function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form string="Partners">' +
|
||||
'<sheet>' +
|
||||
'<field name="product_id"/>' +
|
||||
'<notebook>' +
|
||||
'<page string="Choucroute">' +
|
||||
'<field name="foo"/>' +
|
||||
'</page>' +
|
||||
'<page string="Cassoulet" autofocus="autofocus">' +
|
||||
'<field name="bar"/>' +
|
||||
'</page>' +
|
||||
'</notebook>' +
|
||||
'</sheet>' +
|
||||
'</form>',
|
||||
res_id: 1,
|
||||
});
|
||||
|
||||
assert.notOk(form.$('.o_notebook .nav li:first()').hasClass('active'),
|
||||
'first tab should not active');
|
||||
assert.ok(form.$('.o_notebook .nav li:nth(1)').hasClass('active'),
|
||||
'second tab should be active');
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('invisible attrs on group are re-evaluated on field change', function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user