From ac562ed1e127efc8f9dba2f3a328b6b2f6fb08c0 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 22 Sep 2025 12:08:50 +0100 Subject: [PATCH] Add default question block structure and validation for properties in question editor --- .../templates/atlas/collection_case_questions.html | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/atlas/templates/atlas/collection_case_questions.html b/atlas/templates/atlas/collection_case_questions.html index 4b3f2f00..1b1fbe97 100644 --- a/atlas/templates/atlas/collection_case_questions.html +++ b/atlas/templates/atlas/collection_case_questions.html @@ -268,6 +268,14 @@ currentContent = JSON.parse(JSON.stringify(question_editor.get().json)); } + if (!currentContent) { + currentContent = { + title: questionBlockTitleInput.value || "Case Questions", + type: "object", + properties: {} + }; + } + if (!currentContent.properties) { currentContent.properties = {}; current_question_number = 1; @@ -402,9 +410,13 @@ } catch { currentContent = JSON.parse(JSON.stringify(question_editor.get().json)); } + if (!currentContent || !currentContent.properties) { + console.warn('No properties found in the current content.'); + return; + } const properties = currentContent.properties || {}; - // Sort questions by propertyOrder + // Sort questions by propertyOrder const sortedKeys = Object.keys(properties).sort((a, b) => { const orderA = properties[a].propertyOrder !== undefined ? properties[a].propertyOrder : 1000; const orderB = properties[b].propertyOrder !== undefined ? properties[b].propertyOrder : 1000;