Skip to content

Commit

Permalink
Added validation check for question type (which could be left blank b…
Browse files Browse the repository at this point in the history
…efore) - for story, participant, and annotation questions.
  • Loading branch information
cfkurtz committed Oct 25, 2022
1 parent 492126e commit 164f018
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 9 deletions.
10 changes: 9 additions & 1 deletion webapp/source/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
Expand Down
34 changes: 32 additions & 2 deletions webapp/source/buttonActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down

0 comments on commit 164f018

Please sign in to comment.