This commit is contained in:
Matt Marcha 2024-08-11 10:41:04 -10:00
parent 48e91eba0e
commit 840fa2d704
3 changed files with 14 additions and 1 deletions

View file

@ -2,6 +2,8 @@
import { Component, useState } from "@odoo/owl";
import { TodoItem } from "./todo_item";
import "../utils.js";
import { useAutofocus } from "../utils.js";
export class TodoList extends Component {
static template = "awesome_owl.todo_list";
@ -9,6 +11,7 @@ export class TodoList extends Component {
setup() {
this.todos = useState([]);
useAutofocus('todo_input');
}
addTodo(ev) {

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="awesome_owl.todo_list">
<p><input type="text" name="new-todo" placeholder="Add new todo" t-on-keyup="addTodo" /></p>
<p><input t-ref="todo_input" type="text" name="new-todo" placeholder="Add new todo" t-on-keyup="addTodo" /></p>
<div class="d-inline-block border p-2 m-2">
<t t-foreach="todos" t-as="todo" t-key="todo.id">
<TodoItem todo="todo" />

View file

@ -0,0 +1,10 @@
/** @odoo-module */
import { useRef, onMounted } from "@odoo/owl";
export function useAutofocus(name) {
const ref = useRef(name);
onMounted(() => {
ref.el.focus();
});
}