add: taken slug check
This commit is contained in:
parent
a33ee961fe
commit
d80368e6c2
5 changed files with 85 additions and 7 deletions
|
@ -137,3 +137,34 @@ globalThis.tab_preview = async () => {
|
|||
document.getElementById("editor_tab_button").classList.add("camo");
|
||||
document.getElementById("preview_tab_button").classList.remove("camo");
|
||||
};
|
||||
|
||||
let exists_timeout = null;
|
||||
globalThis.check_exists_input = (e) => {
|
||||
if (exists_timeout) {
|
||||
clearTimeout(exists_timeout);
|
||||
}
|
||||
|
||||
exists_timeout = setTimeout(async () => {
|
||||
if (e.target.value.length < 2 || e.target.value.length > 32) {
|
||||
e.target.setCustomValidity("");
|
||||
e.target.removeAttribute("data-invalid");
|
||||
e.target.reportValidity();
|
||||
return;
|
||||
}
|
||||
|
||||
const exists = (
|
||||
await (await fetch(`/api/v1/entries/${e.target.value}`)).json()
|
||||
).payload;
|
||||
|
||||
console.log(exists);
|
||||
if (exists) {
|
||||
e.target.setCustomValidity("Slug is already in use");
|
||||
e.target.setAttribute("data-invalid", "true");
|
||||
} else {
|
||||
e.target.setCustomValidity("");
|
||||
e.target.removeAttribute("data-invalid");
|
||||
}
|
||||
|
||||
e.target.reportValidity();
|
||||
}, 1000);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue