bradtraversy / javascript-sandbox

Sandbox from the Modern JS From The Beginning 2.0 course
391 stars 424 forks source link

shopping-list project - checkIfItemExists - edit mode #11

Open dmb225 opened 1 month ago

dmb225 commented 1 month ago

Hello.

Thank you for this project. Why don't you check the existence of the object even in edit mode? It's possible that the updated item already exists, isn't it?

  if (isEditMode) {
    const itemToEdit = itemList.querySelector('.edit-mode');

    removeItemFromStorage(itemToEdit.textContent);
    itemToEdit.classList.remove('edit-mode');
    itemToEdit.remove();
    isEditMode = false;
  } else {
    if (checkIfItemExists(newItem)) {
      alert('That item already exists!');
      return;
    }
  }