[FIX] project: default focus set on sub-task title

Issue:
      When user add sub task then first field is focused.
Fixed:
    In this commit, we have made the title the default focus so that the user does not
    have to click manually and time will also be saved.

Steps:
     - Install project app
     - Active Task Dependencies
     - Create task and add subtask

task-3471102

closes odoo/odoo#143251

X-original-commit: 487a62a249e783ca15f95675a6cf43322b61d569
Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
This commit is contained in:
Prakash Prajapati
2023-11-24 16:22:04 +00:00
parent 680eaeff50
commit bbb4a2e08a
2 changed files with 32 additions and 0 deletions
@@ -5,10 +5,23 @@ import { useService } from "@web/core/utils/hooks";
import { ConfirmationDialog } from "@web/core/confirmation_dialog/confirmation_dialog";
import { ListRenderer } from '@web/views/list/list_renderer';
import { useEffect } from "@odoo/owl";
export class SubtaskListRenderer extends ListRenderer {
setup() {
super.setup();
this.dialog = useService("dialog");
useEffect(
() => this.focusName(this.props.list.editedRecord),
() => [this.props.list.editedRecord]
);
}
focusName(editedRecord) {
if (editedRecord?.isNew && !editedRecord.dirty) {
const col = this.state.columns.find((c) => c.name === "name");
this.focusCell(col);
}
}
async onDeleteRecord(record) {
@@ -6,6 +6,7 @@ import { addModelNamesToFetch } from "@bus/../tests/helpers/model_definitions_he
import { start } from "@mail/../tests/helpers/test_utils";
import {
editInput,
click,
getFixture,
clickOpenedDropdownItem,
@@ -68,6 +69,7 @@ QUnit.module('Subtask Kanban List tests', {
<tree editable="bottom">
<field name="display_in_project" force_save="1"/>
<field name="project_id" widget="project"/>
<field name="name"/>
</tree>
</field>
</form>`
@@ -146,8 +148,25 @@ QUnit.module('Subtask Kanban List tests', {
await click(target.querySelector(".o_field_x2many_list_row_add a"));
await clickDropdown(target, 'project_id');
await clickOpenedDropdownItem(target, 'project_id', 'Project One');
await editInput(target, ".o_data_row > td[name='name'] > div > input", "aaa");
await click(target, ".o_form_button_save");
assert.equal(target.querySelector('.o_field_project').textContent.trim(), 'Project One')
});
QUnit.test("focus new subtask's name", async function (assert) {
const views = this.views;
const { openView } = await start({ serverData: { views } });
await openView({
res_model: "project.task",
views: [[false, "form"]],
});
await click(target.querySelector(".o_field_x2many_list_row_add a"));
assert.strictEqual(
document.activeElement,
target.querySelector(".o_data_row > td[name='name'] > div > input"),
"Upon clicking on 'Add a line', the new subtask's name should be focused."
);
});
});