[FIX] survey: fix back button behavior
This commit fixes 2 small problems when the user goes back on the survey form:
- The back button should not be shown on "page_per_question" layout if we are
on the first page of the survey.
Pages can be displayed on "page_per_question" layout if they have a
description since #44271
- Can't go back on "page_per_section" layout if you are on the second page of
the survey, introduced by 0675d68afb
LINKS
PR #48442
Task 2208574
This commit is contained in:
@@ -481,7 +481,7 @@ class Survey(models.Model):
|
||||
current_page_index = pages_or_questions.ids.index(next(p.id for p in pages_or_questions if p.id == page_or_question_id))
|
||||
|
||||
# Get previous and we are on first page OR Get Next and we are on last page
|
||||
if (go_back and current_page_index == 0) or current_page_index == len(pages_or_questions) - 1:
|
||||
if (go_back and current_page_index == 0) or (not go_back and current_page_index == len(pages_or_questions) - 1):
|
||||
return Question
|
||||
|
||||
# Conditional Questions Management
|
||||
|
||||
@@ -202,8 +202,15 @@
|
||||
|
||||
<div class="row">
|
||||
<div class="offset-3 col-6 text-center mt16 mb128">
|
||||
<button t-if="not answer.is_session_answer and survey.users_can_go_back and question != answer.predefined_question_ids[0]" type="submit" class="btn btn-secondary"
|
||||
name="button_submit" value="previous" t-att-data-previous-page-id="previous_page_id">Back</button>
|
||||
<!-- Can go back if:
|
||||
- Back button is allowed in configuration
|
||||
- This is not a session answer (doesn't make sense to go back in session context)
|
||||
- This is not the first question
|
||||
- The survey doesn't have pages OR this is not the first page of the survey
|
||||
(pages are displayed in 'page_per_question' layout when they have a description, see PR#44271)
|
||||
-->
|
||||
<button t-if="survey.users_can_go_back and not answer.is_session_answer and question != answer.predefined_question_ids[0] and (not survey.page_ids or question != survey.page_ids[0])"
|
||||
type="submit" class="btn btn-secondary" name="button_submit" value="previous" t-att-data-previous-page-id="previous_page_id">Back</button>
|
||||
<button type="submit" t-att-value="'next' if not survey_last else 'finish'" class="btn btn-primary">
|
||||
<t t-if="answer.is_session_answer">
|
||||
Submit
|
||||
|
||||
Reference in New Issue
Block a user