Skip to content

Commit

Permalink
Comment more validateAnswer method. Also fix the new StringParser bas…
Browse files Browse the repository at this point in the history
…ed logic to parse the right vaidationParameter-items, but only if they are strings (to prevent JS errors) - #7
  • Loading branch information
andrewhathaway committed Sep 15, 2015
1 parent f9b22c6 commit 196717f
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/lib/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,32 @@ var validateAnswer = (value, validationItem, questionAnswers) => {
}

/*
* Run the value string through the stringParser with the
* Clone the validation parameters so it doesn't effect the
* parameters elsewhere by reference.
*/
var validationParameters = (validationItem.params || []).slice(0);

/*
* Run the parameters through the stringParser with the
* questionAnswers so that it sets the questionAnswer
* as the value.
* as the parameter.
*/
value = StringParser(value, questionAnswers);
validationParameters = validationParameters.map(p => {
return typeof p === 'string'
? StringParser(p, questionAnswers)
: p;
});

/*
* Clone the validation parameters so it doesn't effect the
* parameters by reference. Then push the value to the first
* parameter.
* Push the value of the question we're validating to
* the first parameter of the validationParameters
*/
var validationParameters = (validationItem.params || []).slice(0);
validationParameters.unshift(value);

/*
* Return the result of the validation method running
* wtih the validationParameters.
*/
return validationMethod.apply(null, validationParameters);
};

Expand Down

0 comments on commit 196717f

Please sign in to comment.