Properly validates Integer Survey Question with min value of 0

This commit is contained in:
Alex Corey 2021-09-28 10:37:44 -04:00
parent 7eefa897b3
commit adaa24a562
2 changed files with 7 additions and 4 deletions

View File

@ -72,7 +72,7 @@ function getInitialValues(launchConfig, surveyConfig, resource) {
? question.default.split('\n')
: [];
} else {
values[`survey_${question.variable}`] = question.default || '';
values[`survey_${question.variable}`] = question.default ?? '';
}
if (resource?.extra_data) {
Object.entries(resource.extra_data).forEach(([key, value]) => {
@ -129,11 +129,14 @@ function checkForError(launchConfig, surveyConfig, values) {
}
}
if (isNumeric && (value || value === 0)) {
if (value < question.min || value > question.max) {
if (
(value < question.min || value > question.max) &&
question.required
) {
hasError = true;
}
}
if (question.required && (!value || value.length === 0)) {
if (question.required && (!value || value.length === 0) && !isNumeric) {
hasError = true;
}
});

View File

@ -114,7 +114,7 @@ function SurveyQuestionForm({
variable: question?.variable || '',
min: question?.min || 0,
max: question?.max || 1024,
default: question?.default || '',
default: question?.default ?? '',
choices: question?.choices || '',
formattedChoices: [{ choice: '', isDefault: false, id: 0 }],
new_question: !question,