You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
depot_django/static/js/crud-list.js

37 lines
1.2 KiB
JavaScript

document.addEventListener('DOMContentLoaded', function() {
const editBtn = document.getElementById('editBtn');
const deleteBtn = document.getElementById('deleteBtn');
const objectIdInput = document.getElementById('objectIdInput');
const rows = document.querySelectorAll('.selectable-row');
if (editBtn) {
editBtn.setAttribute('disabled', '');
}
if (deleteBtn) {
deleteBtn.setAttribute('disabled', '');
}
rows.forEach(row => {
row.addEventListener('click', function() {
// Remove previous selection
document.querySelector('.selected-row')?.classList.remove('selected-row');
// Select current row
this.classList.add('selected-row');
const objectId = this.dataset.id;
if (editBtn) {
editBtn.removeAttribute('disabled'); // Remove disabled attribute completely
editBtn.href = editBtn.dataset.url.replace('0', objectId);
}
if (deleteBtn) {
deleteBtn.removeAttribute('disabled');
}
// Check the hidden radio button
const radio = this.querySelector('input[type="radio"]');
radio.checked = true;
});
});
});