mirror of
https://github.com/SinTan1729/chhoto-url
synced 2024-12-26 07:38:36 -06:00
Refactor error box adding
This commit is contained in:
parent
6e2f1df108
commit
3d239c189c
1 changed files with 11 additions and 6 deletions
|
@ -20,6 +20,15 @@ const displayData = (data) => {
|
|||
.forEach(tr => table.appendChild(tr));
|
||||
};
|
||||
|
||||
const addErrBox = () => {
|
||||
const controls = document.querySelector(".pure-controls");
|
||||
const errBox = document.createElement("p");
|
||||
errBox.setAttribute("id", "errBox");
|
||||
errBox.setAttribute("style", "color:red");
|
||||
errBox.innerHTML = "Short URL not valid or already in use!";
|
||||
controls.appendChild(errBox);
|
||||
}
|
||||
|
||||
const TR = (row) => {
|
||||
const tr = document.createElement("tr");
|
||||
const longTD = TD(A(row.long));
|
||||
|
@ -73,14 +82,10 @@ const submitForm = () => {
|
|||
body: `${longUrl.value};${shortUrl.value}`
|
||||
})
|
||||
.then((res) => {
|
||||
console.log("0");
|
||||
if (!res.ok) {
|
||||
if (document.getElementById("errBox") == null) {
|
||||
const controls = document.querySelector(".pure-controls");
|
||||
const errBox = document.createElement("p");
|
||||
errBox.setAttribute("id", "errBox");
|
||||
errBox.setAttribute("style", "color:red");
|
||||
errBox.innerHTML = "Short URL not valid or already in use!";
|
||||
controls.appendChild(errBox);
|
||||
addErrBox();
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Reference in a new issue