2020-11-22 14:57:25 +01:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
const form = document.getElementById('url-shrink-form');
|
|
|
|
if (!form) return;
|
|
|
|
|
|
|
|
const autogenUrlCheckbox = document.querySelector<HTMLInputElement>('#field-autogen_url');
|
|
|
|
const slugField = document.querySelector<HTMLInputElement>('#field-slug');
|
|
|
|
|
2021-03-30 14:30:04 +02:00
|
|
|
if (slugField && autogenUrlCheckbox) {
|
|
|
|
const updateSlugField = () => {
|
2020-11-22 14:57:25 +01:00
|
|
|
slugField.disabled = autogenUrlCheckbox.checked;
|
2021-03-30 14:30:04 +02:00
|
|
|
|
|
|
|
const parent = slugField.parentElement?.parentElement;
|
|
|
|
if (parent) {
|
|
|
|
if (autogenUrlCheckbox.checked) {
|
|
|
|
parent.classList.add('hidden');
|
|
|
|
} else {
|
|
|
|
parent.classList.remove('hidden');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
autogenUrlCheckbox.addEventListener('change', updateSlugField);
|
|
|
|
updateSlugField();
|
2020-11-22 14:57:25 +01:00
|
|
|
}
|
|
|
|
});
|