diff --git a/webapp/source/Application.ts b/webapp/source/Application.ts index 6a565300..05d8d5f6 100644 --- a/webapp/source/Application.ts +++ b/webapp/source/Application.ts @@ -147,10 +147,18 @@ class Application { const itemID = fieldSpecification.value; let success = buttonActions.checkThatItemHasShortName(itemID); return success ? null : ["You must enter a short name for this item."]; - } else if (functionName === "requireShortNameAndQuestionOptionsIfNecessary") { + } else if (functionName === "requireShortNameAndType") { const itemID = fieldSpecification.value; let success = buttonActions.checkThatItemHasShortName(itemID); if (!success) return ["You must enter a short name for this item."]; + success = buttonActions.checkThatQuestionHasType(itemID); + return success ? null : ["You must enter a question type for this item."]; + } else if (functionName === "requireShortNameTypeAndQuestionOptionsIfNecessary") { + const itemID = fieldSpecification.value; + let success = buttonActions.checkThatItemHasShortName(itemID); + if (!success) return ["You must enter a short name for this item."]; + success = buttonActions.checkThatQuestionHasType(itemID); + if (!success) return ["You must enter a question type for this item."]; success = buttonActions.checkThatItemHasOptionListIfRequired(itemID); return success ? null : ["You must enter at least two options for this type of question."]; } else { diff --git a/webapp/source/applicationPanelSpecifications/collection/page_writeQuestionsAboutParticipants.ts b/webapp/source/applicationPanelSpecifications/collection/page_writeQuestionsAboutParticipants.ts index 670f4f48..7ee2ee58 100644 --- a/webapp/source/applicationPanelSpecifications/collection/page_writeQuestionsAboutParticipants.ts +++ b/webapp/source/applicationPanelSpecifications/collection/page_writeQuestionsAboutParticipants.ts @@ -27,8 +27,8 @@ const panel: Panel = { columnsToDisplay: ["participantQuestion_text", "participantQuestion_type", "participantQuestion_shortName", "participantQuestion_options"], viewButton: true, editButton: true, - validateAdd: "requireShortNameAndQuestionOptionsIfNecessary", - validateEdit: "requireShortNameAndQuestionOptionsIfNecessary", + validateAdd: "requireShortNameTypeAndQuestionOptionsIfNecessary", + validateEdit: "requireShortNameTypeAndQuestionOptionsIfNecessary", addButton: true, removeButton: true, navigationButtons: true, diff --git a/webapp/source/applicationPanelSpecifications/collection/page_writeQuestionsAboutStories.ts b/webapp/source/applicationPanelSpecifications/collection/page_writeQuestionsAboutStories.ts index fb7c600c..c858dc25 100644 --- a/webapp/source/applicationPanelSpecifications/collection/page_writeQuestionsAboutStories.ts +++ b/webapp/source/applicationPanelSpecifications/collection/page_writeQuestionsAboutStories.ts @@ -26,8 +26,8 @@ const panel: Panel = { columnsToDisplay: ["storyQuestion_text", "storyQuestion_type", "storyQuestion_shortName", "storyQuestion_options"], viewButton: true, editButton: true, - validateAdd: "requireShortNameAndQuestionOptionsIfNecessary", - validateEdit: "requireShortNameAndQuestionOptionsIfNecessary", + validateAdd: "requireShortNameTypeAndQuestionOptionsIfNecessary", + validateEdit: "requireShortNameTypeAndQuestionOptionsIfNecessary", addButton: true, removeButton: true, navigationButtons: true, diff --git a/webapp/source/applicationPanelSpecifications/collection/page_writeStoryElicitingQuestions.ts b/webapp/source/applicationPanelSpecifications/collection/page_writeStoryElicitingQuestions.ts index 66584c1a..cee9c78d 100644 --- a/webapp/source/applicationPanelSpecifications/collection/page_writeStoryElicitingQuestions.ts +++ b/webapp/source/applicationPanelSpecifications/collection/page_writeStoryElicitingQuestions.ts @@ -29,8 +29,8 @@ const panel: Panel = { editButton: true, addButton: true, removeButton: true, - validateAdd: "requireShortName", - validateEdit: "requireShortName", + validateAdd: "requireShortNameAndType", + validateEdit: "requireShortNameAndType", navigationButtons: true, columnsToDisplay: ["elicitingQuestion_text", "elicitingQuestion_shortName"] } diff --git a/webapp/source/buttonActions.ts b/webapp/source/buttonActions.ts index 11167186..975a7cc8 100644 --- a/webapp/source/buttonActions.ts +++ b/webapp/source/buttonActions.ts @@ -310,6 +310,31 @@ export function checkThatItemHasShortName(itemID): boolean { return item[shortNameKey] && item[shortNameKey].length > 0; } +export function checkThatQuestionHasType(itemID): boolean { + if (!itemID) return false; + const item = project.tripleStore.makeObject(itemID, true); + if (!item) return false; + + // item types where question types are required, for lookup: + // story, participant, and annotation questions + + let itemType = null; + if (itemID.indexOf("StoryQuestion") >= 0) { + itemType = "storyQuestion"; + } else if (itemID.indexOf("ParticipantQuestion") >= 0) { + itemType = "participantQuestion"; + } else if (itemID.indexOf("AnnotationQuestion") >= 0) { + itemType = "annotationQuestion"; + } else { + const message = "Error: Unsupported question type validation check for item: " + itemID; + alert(message); + console.log(message); + } + + const questionType = item[itemType + "_type"]; + return (questionType && questionType.length > 0); +} + export function checkThatItemHasOptionListIfRequired(itemID): boolean { if (!itemID) return false; const item = project.tripleStore.makeObject(itemID, true); @@ -331,8 +356,13 @@ export function checkThatItemHasOptionListIfRequired(itemID): boolean { const questionType = item[itemType + "_type"]; if (["radiobuttons", "select", "checkboxes"].indexOf(questionType) >= 0) { - const questionOptions = item[itemType + "_options"].split("\n"); - return (questionOptions && questionOptions.length > 1); + const questionOptionsString = item[itemType + "_options"]; + if (questionOptionsString) { + const questionOptionsList = item[itemType + "_options"].split("\n"); + return (questionOptionsList.length > 1); + } else { + return false; + } } else { return true; }