mirror of
https://github.com/cse110-fa22-group29/cse110-fa22-group29.git
synced 2025-09-10 00:27:20 +00:00
No tag duplicates
This commit is contained in:
@@ -3,11 +3,7 @@ import { newReviewToStorage } from "./localStorage.js";
|
||||
window.addEventListener("DOMContentLoaded", init);
|
||||
|
||||
function init() {
|
||||
// get next id
|
||||
|
||||
// creates the key
|
||||
initFormHandler();
|
||||
|
||||
}
|
||||
|
||||
function initFormHandler() {
|
||||
@@ -91,19 +87,26 @@ function initFormHandler() {
|
||||
});
|
||||
|
||||
let tagAddBtn = document.getElementById("tag-add-btn");
|
||||
//Set used to track tags and ensure no duplicates
|
||||
let tagSet = new Set();
|
||||
tagAddBtn.addEventListener("click", ()=> {
|
||||
let tagField = document.getElementById("tag-form");
|
||||
if (tagField.value.length > 0) {
|
||||
let tagLabel = document.createElement("label");
|
||||
tagLabel.innerHTML = tagField.value;
|
||||
tagLabel.setAttribute("class","tag");
|
||||
tagLabel.addEventListener("click",()=> {
|
||||
tagContainer.removeChild(tagLabel);
|
||||
});
|
||||
|
||||
tagContainer.append(tagLabel);
|
||||
if (!tagSet.has(tagField.value.toLowerCase())){
|
||||
let tagLabel = document.createElement("label");
|
||||
tagLabel.innerHTML = tagField.value;
|
||||
tagLabel.setAttribute("class","tag");
|
||||
tagSet.add(tagField.value.toLowerCase());
|
||||
tagLabel.addEventListener("click",()=> {
|
||||
tagContainer.removeChild(tagLabel);
|
||||
tagSet.delete(tagField.value.toLowerCase());
|
||||
});
|
||||
|
||||
tagContainer.append(tagLabel);
|
||||
} else {
|
||||
window.alert("No duplicate tags allowed");
|
||||
}
|
||||
tagField.value = "";
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user