Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handled error #96
Browse files Browse the repository at this point in the history
cosbyr committed Nov 1, 2018
1 parent 8fcf8cc commit aac02da
Showing 3 changed files with 39 additions and 13 deletions.
1 change: 1 addition & 0 deletions js/app/main.js
Original file line number Diff line number Diff line change
@@ -438,6 +438,7 @@ define(['lib/i18n.min!nls/resources.js', 'prepareAppConfigInfo', 'handleUserSign
// Provide the i18n strings to the survey
survey.flag_important_question = i18n.tooltips.flag_important_question;
survey.error_text = i18n.messages.error_text;
survey.domain_error_text = i18n.messages.domain_error_text;



48 changes: 36 additions & 12 deletions js/app/survey.js
Original file line number Diff line number Diff line change
@@ -312,6 +312,22 @@ define([], function () {
return surveyQuestions;
},

/**
* Creates a survey form in the specified element.
* @param {object} questionInfo Survey question, which contains question, field, style, domain, important
*/
_checkDomain: function(questionInfo){
var reqDomain = ["button", "list", "dropdown"];
if (!isNaN(questionInfo.domain) && (reqDomain.includes(questionInfo.style))){
return false;
}
else{
return true;
}
},



/**
* Creates a survey form in the specified element.
* @param {div} surveyContainer Element containing survey form
@@ -323,7 +339,7 @@ define([], function () {
_addQuestion: function (surveyContainer, iQuestion, questionInfo, isReadOnly) {
var question = survey._startQuestion(iQuestion, questionInfo);
//Question Object Needs to exist in order for HTML element to be created
if (questionInfo){
if (questionInfo && survey._checkDomain(questionInfo)){
//Create parent flags if question type is parent (domain value 0)
var primeQFlag = questionInfo.questionType === 0 ? "prime" : " contingent";
primeQFlag = questionInfo.style === "dropdown" ? "primeD" : primeQFlag;
@@ -384,17 +400,25 @@ define([], function () {

//Check for question info object
if (questionInfo){
// Determine whether to show question on first load. Applies to questions with no parents
var initDisplay = !questionInfo.parent ? "" : " style='display: none;'";
var start =
"<div id='qg" + iQuestion + "' class='form-group'" + initDisplay + ">"
+ "<label for='q" + iQuestion + "'>" + questionInfo.question + (questionInfo.important
? "&nbsp;<div class='importantQuestion sprites star' title=\""
+ survey.flag_important_question + "\"></div>"
: "")
+ "</label><br>";
if (questionInfo.image && questionInfo.image.length > 0 && questionInfo.imagepos === "Before") {
start += "<img src='" + questionInfo.image + "' class='image-before'/><br>";
//Check to see if button, list, and dropdown questions have a domain set
var reqDomain = ["button", "list", "dropdown"];
if (!survey._checkDomain(questionInfo)){
var start = "<div id = 'qg" + iQuestion + "' class='form-group' style='color: red'>" +
survey.domain_error_text.replace("${0}", iQuestion) +"<br></div>"
}
else{
// Determine whether to show question on first load. Applies to questions with no parents
var initDisplay = !questionInfo.parent ? "" : " style='display: none;'";
var start =
"<div id='qg" + iQuestion + "' class='form-group'" + initDisplay + ">"
+ "<label for='q" + iQuestion + "'>" + questionInfo.question + (questionInfo.important
? "&nbsp;<div class='importantQuestion sprites star' title=\""
+ survey.flag_important_question + "\"></div>"
: "")
+ "</label><br>";
if (questionInfo.image && questionInfo.image.length > 0 && questionInfo.imagepos === "Before") {
start += "<img src='" + questionInfo.image + "' class='image-before'/><br>";
}
}
}
//If object is not defined or null then display it with error text
3 changes: 2 additions & 1 deletion nls/resources.js
Original file line number Diff line number Diff line change
@@ -53,7 +53,8 @@ define({
guestLabel: "Guest"
},
messages: {
error_text: "Question ${0} Error displaying question, please check that field name from survey question table matches the photo points feature service"
error_text: "Question ${0} Error displaying question, please check that field name from survey question table matches the photo points feature service",
domain_error_text: "Question ${0} Error displaying question. Button, list, and dropdown style questions require that the associated field has a domain."
}
}),
"ar": 0,

2 comments on commit aac02da

@MikeTschudi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cosbyr, What is the purpose of var reqDomain = ["button", "list", "dropdown"]; in _startQuestion?

While we support and test translation for this app, it isn't translated as a product, so there's no need to notify the i18n team. Please add the domain_error_text line to the de\resources.js and fr\resources.js sample files, however, so that the app doesn't fail in those example languages.

@cosbyr
Copy link
Contributor Author

@cosbyr cosbyr commented on aac02da Nov 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MikeTschudi Good catch. I copied that var reqDomain line into a helper function and forgot to get rid of it in _startQuestion.

Please sign in to comment.