Add category filter to set question selection
This commit is contained in:
@@ -12,8 +12,46 @@ HTMLHelper::_('behavior.formvalidator');
|
||||
<?php echo $this->form->renderField('title'); ?>
|
||||
<?php echo $this->form->renderField('description'); ?>
|
||||
<?php echo $this->form->renderField('published'); ?>
|
||||
<?php echo $this->form->renderField('question_ids'); ?>
|
||||
<div class="mb-3">
|
||||
<label for="set-question-category" class="form-label"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_CATEGORY_FILTER'); ?></label>
|
||||
<select id="set-question-category" class="form-select">
|
||||
<option value=""><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_ALL_CATEGORIES'); ?></option>
|
||||
<?php foreach ($this->categories as $category) : ?>
|
||||
<option value="<?php echo (int) $category->id; ?>"><?php echo $this->escape($category->title); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<fieldset class="mb-3">
|
||||
<legend><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_QUESTIONS'); ?></legend>
|
||||
<div id="set-question-list" class="border rounded p-3">
|
||||
<?php foreach ($this->questions as $question) : ?>
|
||||
<div class="form-check set-question-row" data-category="<?php echo (int) $question->category_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; ?>" <?php echo in_array((int) $question->id, (array) $this->item->question_ids, true) ? 'checked' : ''; ?>>
|
||||
<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>
|
||||
<?php echo $this->escape(trim(strip_tags($question->question))); ?>
|
||||
</label>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</fieldset>
|
||||
</fieldset>
|
||||
<input type="hidden" name="task" value="">
|
||||
<?php echo HTMLHelper::_('form.token'); ?>
|
||||
</form>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const filter = document.getElementById('set-question-category');
|
||||
const rows = document.querySelectorAll('.set-question-row');
|
||||
|
||||
if (!filter) {
|
||||
return;
|
||||
}
|
||||
|
||||
filter.addEventListener('change', function () {
|
||||
rows.forEach(function (row) {
|
||||
row.classList.toggle('d-none', filter.value !== '' && row.dataset.category !== filter.value);
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user