-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtodoForm.js
More file actions
44 lines (35 loc) · 1.16 KB
/
todoForm.js
File metadata and controls
44 lines (35 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import Validator from './validator.js';
import Todo from './todo.js';
export default class TodoForm {
constructor() {
this.form = document.getElementById('addTodoForm');
this.input = this.form.querySelector('input');
this.openFormButton = document.getElementById('addToDo');
this.formOverlay = document.getElementById('addTodoOverlay');
this.openFormButton.addEventListener('click', this.showFormHandler.bind(this));
this.formOverlay.addEventListener('click', this.hideFormHandler.bind(this));
this.form.addEventListener('submit', this.submitHandler.bind(this));
}
showFormHandler() {
this.form.classList.remove('invisible');
this.formOverlay.classList.remove('invisible');
}
hideFormHandler() {
this.form.classList.add('invisible');
this.formOverlay.classList.add('invisible');
this.clearFormInput();
}
clearFormInput() {
this.input.value = '';
}
submitHandler(event) {
event.preventDefault();
const inputValue = this.input.value;
if (!Validator.validate(inputValue)) {
return;
}
const newTodo = new Todo(inputValue, false);
newTodo.pushData();
this.hideFormHandler();
}
}