Skip to content

Commit 0b670db

Browse files
committed
[IMP] awesome_owl: add the possibility to add todoitem
Add an inupt field in the todolist. Link a function to this input to create new todoitem with: - the value of the input as description of the todo - last_id +1 as id It doesn't creaete anything if the input is empty
1 parent 8447731 commit 0b670db

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

awesome_owl/static/src/todolist/todolist.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,25 @@ export class TodoList extends Component {
77
static components = { TodoItem };
88

99
setup() {
10-
this.todos = useState([
11-
{ id: 3, description: "buy milk", isCompleted: false },
12-
{ id: 4, description: "Go to work", isCompleted: true },
13-
14-
]);
10+
this.todos = useState([]);
1511
}
1612

17-
}
13+
addTodo(ev) {
14+
if (ev.keyCode === 13) {
15+
16+
console.debug(this.todos);
17+
console.debug(this.todos.length);
18+
var todoId;
19+
if (this.todos.length == 0) {
20+
todoId = 1;
21+
} else {
22+
todoId = this.todos[this.todos.length -1].id + 1;
23+
}
24+
var content = document.querySelector(".todo_content");
25+
if (content.value != "") {
26+
this.todos.push({ id: todoId, description: content.value, isCompleted: false });
27+
content.value = "";
28+
}
29+
}
30+
}
31+
}

awesome_owl/static/src/todolist/todolist.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
<t t-name="awesome_owl.todolist">
55
<div class="card d-inline-block m-2">
6+
<input class="todo_content" placeholder="Enter a new task" t-on-keyup="ev => this.addTodo(ev)"/>
67
<t t-foreach="todos" t-as="i" t-key="i.id">
78
<TodoItem todo="i"/>
89
</t>

0 commit comments

Comments
 (0)