web: only auto-update slug when slug and name are already in sync

This commit is contained in:
Jens Langhammer 2020-12-12 23:45:47 +01:00
parent 434922f702
commit 1524061480
1 changed files with 14 additions and 8 deletions

View File

@ -64,7 +64,6 @@ export class ModalButton extends LitElement {
}); });
// Make name field update slug field // Make name field update slug field
this.querySelectorAll<HTMLInputElement>("input[name=name]").forEach((input) => { this.querySelectorAll<HTMLInputElement>("input[name=name]").forEach((input) => {
input.addEventListener("input", () => {
const form = input.closest("form"); const form = input.closest("form");
if (form === null) { if (form === null) {
return; return;
@ -73,6 +72,13 @@ export class ModalButton extends LitElement {
if (!slugField) { if (!slugField) {
return; return;
} }
// Only attach handler if the slug is already equal to the name
// if not, they are probably completely different and shouldn't update
// each other
if (convertToSlug(input.value) !== slugField.value) {
return;
}
input.addEventListener("input", () => {
slugField.value = convertToSlug(input.value); slugField.value = convertToSlug(input.value);
}); });
}); });