I am doing a to do list in wix.com using javascript. Now I want to get the text that the user have entered with a button which works great and with the enter key as well which doesn"t work and I have no idea why.
import wixData from 'wix-data';
async function addNewTask() {
const taskTitle = $w('#taskInput').value;
if (taskTitle.length !== 0) {
const newTask = {
title: taskTitle,
completed: false
}
await wixData.insert('Tasks', newTask);
$w('#taskInput').value = '';
await $w('#tasksDataset').refresh();
}
}
export async function taskInput_keyPress(event) {
if (event.key === 'Enter') {
await addNewTask();
}
}
export async function addTaskButton_click(event) {
await addNewTask();
}
You value seems to be a hidden one, you can give it a try.
if (event.key === "Enter") { await addNewTask().show(); }