Skip to content

Commit

Permalink
[new] isValid function for questions
Browse files Browse the repository at this point in the history
  • Loading branch information
blcham committed Nov 27, 2016
1 parent 0bda2cf commit 5d42bd1
Showing 1 changed file with 40 additions and 7 deletions.
47 changes: 40 additions & 7 deletions src/util/FormUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,55 @@ export default class FormUtils {
return false;
}

static isValid(question) {
var subQ;

if (question[Constants.HAS_VALID_ANSWER] === false) {
return false;
}
for (subQ of Utils.asArray(question[Constants.HAS_SUBQUESTION])) {
if (this.isValid(subQ) === false) {
return false;
}
}

return true;
}

static testCondition(condition) {

var questionsWithValidAnswer = condition[Constants.HAS_VALID_ANSWER],
var acceptedValidationsValues = condition[Constants.ACCEPTS_VALIDATION_VALUE],
acceptedAnswerValues = condition[Constants.ACCEPTS_ANSWER_VALUE],
testedQuestion = condition[Constants.HAS_TESTED_QUESTION];
testedQuestions = condition[Constants.HAS_TESTED_QUESTION],
q, question;

if (acceptedValidationsValues && acceptedAnswerValues) {
console.warn("Support for validation and requirement constraints at same time is not implemented !");
}

// valid answers
if (questionsWithValidAnswer) {
for (var question of Utils.asArray(questionsWithValidAnswer)) {
return true; //TODO not implemented
if (acceptedValidationsValues && testedQuestions) {

var arr = Utils.asArray(acceptedValidationsValues);
if ((arr.length !== 1) || ((arr[0] !== true) && (arr[0] !== "true"))) {
console.warn("Validation values other than \"true\" are not implemented !");
}
for (q of Utils.asArray(testedQuestions)) {
question = JsonObjectMap.getObject(q["@id"]);
if (question === undefined) {
console.warn("Questions is not loaded in an object map.");
return true;
}
if (this.isValid(question) === false) {
return false;
}
}
return true;
}

// concrete values
if (acceptedAnswerValues && testedQuestion) {
var question = JsonObjectMap.getObject(testedQuestion["@id"]);
if (acceptedAnswerValues && testedQuestions) {
question = JsonObjectMap.getObject(testedQuestions["@id"]);
for (var expValue of Utils.asArray(acceptedAnswerValues)) {
var answers = jsonld.getValues(question, Constants.HAS_ANSWER);

Expand Down

0 comments on commit 5d42bd1

Please sign in to comment.