-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.js
34 lines (28 loc) · 1.05 KB
/
config.js
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
function openPlayerConfig(event) {
editedPlayer = +event.target.dataset.playerid;
playerConfigOverlayElement.style.display = "block";
backdropElement.style.display = "block";
}
function closedPlayerConfig() {
playerConfigOverlayElement.style.display = "none";
backdropElement.style.display = "none";
formElement.firstElementChild.classList.remove("error");
errorsOutputElement.textContent = "";
formElement.firstElementChild.lastElementChild.value = "";
}
function savePlayerConfig(event) {
event.preventDefault();
const formData = new FormData(event.target);
const enteredPlayerName = formData.get("username").trim();
if (!enteredPlayerName) {
event.target.firstElementChild.classList.add("error");
errorsOutputElement.textContent = "Please enter a valid name!";
return;
}
const updatedPlayerDataElement = document.getElementById(
"player-" + editedPlayer + "-data"
);
updatedPlayerDataElement.children[1].textContent = enteredPlayerName;
players[editedPlayer - 1].name = enteredPlayerName;
closedPlayerConfig();
}