Skip to content

Commit

Permalink
add key handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
DanZalov committed Mar 10, 2024
1 parent 9627697 commit 51c3047
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/components/TaskForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (props.taskId) {
const isNew = !props.taskId
const submitForm = () => {
function submitForm() {
if (newTitle.value) {
if (isNew) {
store.addTask({ title: newTitle.value, id: Date.now().toString() })
Expand All @@ -25,11 +25,23 @@ const submitForm = () => {
newTitle.value = ''
}
}
function escHandler() {
newTitle.value = ''
emit('close')
}
</script>

<template>
<div class="task">
<input type="text" v-model="newTitle" placeholder="Название задачи" required />
<input
type="text"
v-model="newTitle"
placeholder="Название задачи"
@keydown.enter="submitForm"
@keydown.esc="escHandler"
required
/>
<button type="submit" :class="isNew ? 'primary' : 'green'" @click="submitForm">
{{ isNew ? 'Добавить' : 'Обновить' }}
</button>
Expand Down

0 comments on commit 51c3047

Please sign in to comment.