update code
This commit is contained in:
@@ -175,10 +175,13 @@
|
||||
<?php for ($i = 0; $i < $rowsCount; $i++): ?>
|
||||
<div class="row g-2 align-items-end mb-2 unit-chapter-entry">
|
||||
<div class="col">
|
||||
<input type="text" name="unit_<?= esc($slug) ?>[]" class="form-control form-control-sm" placeholder="Unit name" value="<?= esc($unitValues[$i] ?? '') ?>">
|
||||
<input type="text" name="unit_<?= esc($slug) ?>[]" class="form-control form-control-sm" placeholder="Unit name" value="<?= esc($unitValues[$i] ?? '') ?>" readonly>
|
||||
</div>
|
||||
<div class="col">
|
||||
<input type="text" name="chapter_<?= esc($slug) ?>[]" class="form-control form-control-sm" placeholder="Chapter" value="<?= esc($chapterValues[$i] ?? '') ?>">
|
||||
<input type="text" name="chapter_<?= esc($slug) ?>[]" class="form-control form-control-sm" placeholder="Chapter" value="<?= esc($chapterValues[$i] ?? '') ?>" readonly>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<button type="button" class="btn btn-outline-danger btn-sm" data-remove-unit-chapter aria-label="Remove entry">X</button>
|
||||
</div>
|
||||
</div>
|
||||
<?php endfor; ?>
|
||||
@@ -263,10 +266,13 @@
|
||||
row.className = 'row g-2 align-items-end mb-2 unit-chapter-entry';
|
||||
row.innerHTML = `
|
||||
<div class="col">
|
||||
<input type="text" name="unit_${slug}[]" class="form-control form-control-sm" placeholder="Unit name" />
|
||||
<input type="text" name="unit_${slug}[]" class="form-control form-control-sm" placeholder="Unit name" readonly />
|
||||
</div>
|
||||
<div class="col">
|
||||
<input type="text" name="chapter_${slug}[]" class="form-control form-control-sm" placeholder="Chapter" />
|
||||
<input type="text" name="chapter_${slug}[]" class="form-control form-control-sm" placeholder="Chapter" readonly />
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<button type="button" class="btn btn-outline-danger btn-sm" data-remove-unit-chapter aria-label="Remove entry">X</button>
|
||||
</div>
|
||||
`;
|
||||
const inputs = row.querySelectorAll('input');
|
||||
@@ -338,6 +344,15 @@
|
||||
});
|
||||
});
|
||||
|
||||
document.addEventListener('click', event => {
|
||||
const button = event.target.closest('[data-remove-unit-chapter]');
|
||||
if (!button) return;
|
||||
const row = button.closest('.unit-chapter-entry');
|
||||
if (row) {
|
||||
row.remove();
|
||||
}
|
||||
});
|
||||
|
||||
document.querySelectorAll('[data-custom-entry]').forEach(button => {
|
||||
button.addEventListener('click', event => {
|
||||
event.stopPropagation();
|
||||
|
||||
Reference in New Issue
Block a user