From 90807b378adc3cf19bd404d2954dcb4fed85c203 Mon Sep 17 00:00:00 2001 From: Martijn van de Rijdt Date: Thu, 30 Nov 2023 15:24:13 -0500 Subject: [PATCH] fixed: loading to the wrong page if the first page contains no dn widget, #720 emporary duplicate fix that can be reverted later, --- public/js/src/module/page.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/public/js/src/module/page.js b/public/js/src/module/page.js index 59ea69bf4..4296150eb 100644 --- a/public/js/src/module/page.js +++ b/public/js/src/module/page.js @@ -6,6 +6,34 @@ import reasons from './reasons'; import settings from './settings'; import gui from './gui'; + +// Contains fix for https://github.com/OpenClinica/enketo-express-oc/issues/720 +// This function should be removed once PR https://github.com/enketo/enketo/pull/1286 is merged +// and published +pageModule.flipToPageContaining = function($e) { + const e = $e[0]; + const closestPage = e.closest('[role="page"]'); + + if (closestPage) { + this._flipTo(closestPage); + } else if (e.closest('.question')) { + // If $e is a comment question, and it is not inside a group, there will be no closestPage. + const referer = e.querySelector('[data-for]'); + const ancestor = e.closest('.or-repeat, form.or'); + if (referer && ancestor) { + const linkedQuestion = ancestor.querySelector( + `[name="${referer.dataset.for}"]` + ); + if (linkedQuestion) { + this._flipTo(linkedQuestion.closest('[role="page"]')); + } + } + } + this.$toc.parent().find('.pages-toc__overlay').click(); +}, + + + /* * The only thing we want to change in this function for OC, * is to NOT flip to the next page when a repeat is the same as a page and