Skip to content

Commit

Permalink
add no question focus option in submission navigation
Browse files Browse the repository at this point in the history
now the default navigation has no question focus,
meaning that `Tab` does not skip other questions.
Initial cursor focus remains on question 1
even when no question filter is selected
  • Loading branch information
IonMich committed Feb 24, 2024
1 parent 5f07092 commit 5a752f1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 9 additions & 5 deletions submissions/static/submissions/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,13 @@ async function handleScroll () {
console.log(`focusing on input[data-position="${initialFocusQuestionIndex}"]`);

// remove tabindex from all other grade inputs
grade_inputs.forEach((input, i) => {
if (i !== initialFocusQuestionIndex) {
input.setAttribute("tabindex", "-1");
}
});
if (hasInitialFocusQuestionIndex) {
grade_inputs.forEach((input, i) => {
if (i !== initialFocusQuestionIndex) {
input.setAttribute("tabindex", "-1");
}
});
}
} else {
const firstGradeInput = document.querySelector(`input[data-position="0"]`);
console.log(`Failed. Focusing on first grade input because input[data-position="${initialFocusQuestionIndex}"] does not exist`);
Expand Down Expand Up @@ -481,11 +483,13 @@ if (pk === firstPk) {

// try to get the initial focus question index from the url question_focus parameter
let initialFocusQuestionIndex = 0;
let hasInitialFocusQuestionIndex = false;
try {
const urlParams = new URLSearchParams(location.search);
const questionFocus = urlParams.get("question_focus");
if (questionFocus) {
initialFocusQuestionIndex = parseInt(questionFocus);
hasInitialFocusQuestionIndex = true;
}
} catch (error) {
console.log(`No question_focus parameter in url`);
Expand Down
6 changes: 2 additions & 4 deletions submissions/templates/submissions/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -670,13 +670,11 @@ <h5 class="mt-5">Set navigation filters</h5>
<label class="mt-3" for="id_filter_question" style="font-size:20px;">Focus on Question</label>
<div class="mt-2">
<select class="form-control selectpicker show-tick" data-show-subtext="true" title="Select question" data-live-search="true" name="filter_question" id="id_filter_question">
{% comment %} <option data-hidden="true" value=""></option> {% endcomment %}
<option value="">No filter</option>
{% with ''|center:submission.assignment.number_of_questions as range %}
{% for i in range %}
<option value="{{ forloop.counter0 }}"
{% if forloop.counter0 == 0 and query_params.question_focus is None %}
selected
{% elif forloop.counter0|slugify in query_params.question_focus|slugify %}
{% if forloop.counter0|slugify in query_params.question_focus|slugify %}
selected
{% endif %}

Expand Down

0 comments on commit 5a752f1

Please sign in to comment.