Add question ID filter to set editor

This commit is contained in:
Wojtek
2026-10-16 20:54:05 +02:00
parent 887b27f30b
commit 9af456989a
5 changed files with 25 additions and 7 deletions
@@ -102,10 +102,14 @@ HTMLHelper::_('behavior.formvalidator');
<?php endforeach; ?>
</select>
</div>
<div class="mb-3">
<label for="set-question-ids" class="form-label"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_ID_FILTER'); ?></label>
<input type="text" id="set-question-ids" class="form-control" placeholder="<?php echo $this->escape(\Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_ID_FILTER_HINT')); ?>" inputmode="numeric">
</div>
<div id="set-available-question-list" class="border rounded p-3">
<?php foreach ($this->questions as $question) : ?>
<?php if (in_array((int) $question->id, array_map('intval', (array) $this->item->question_ids), true)) continue; ?>
<div class="form-check set-available-question-row" data-category="<?php echo (int) $question->category_id; ?>">
<div class="form-check set-available-question-row" data-category="<?php echo (int) $question->category_id; ?>" data-id="<?php echo (int) $question->id; ?>">
<input class="form-check-input" type="checkbox" name="jform[question_ids][]" value="<?php echo (int) $question->id; ?>" id="set-question-<?php echo (int) $question->id; ?>">
<label class="form-check-label" for="set-question-<?php echo (int) $question->id; ?>">
<span class="badge bg-secondary"><?php echo $this->escape($question->category_title ?: \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_UNCATEGORIZED')); ?></span>
@@ -181,17 +185,28 @@ document.addEventListener('DOMContentLoaded', function () {
<script>
document.addEventListener('DOMContentLoaded', function () {
const filter = document.getElementById('set-question-category');
const idFilter = document.getElementById('set-question-ids');
const rows = document.querySelectorAll('.set-available-question-row');
if (!filter) {
if (!filter || !idFilter) {
return;
}
filter.addEventListener('change', function () {
const applyFilters = function () {
const requestedIds = idFilter.value
.split(',')
.map(function (value) { return value.trim(); })
.filter(function (value) { return value !== ''; });
rows.forEach(function (row) {
row.classList.toggle('d-none', filter.value !== '' && row.dataset.category !== filter.value);
const matchesCategory = filter.value === '' || row.dataset.category === filter.value;
const matchesId = requestedIds.length === 0 || requestedIds.includes(row.dataset.id);
row.classList.toggle('d-none', !matchesCategory || !matchesId);
});
});
};
filter.addEventListener('change', applyFilters);
idFilter.addEventListener('input', applyFilters);
});
</script>
<script>