Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/Service/SubmissionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,10 @@ public function validateSubmission(array $questions, array $answers, string $for
}
}

// Handle custom validation of short answers
if ($question['type'] === Constants::ANSWER_TYPE_SHORT && !$this->validateShortQuestion($question, $answers[$questionId][0])) {
// Handle custom validation of short answers, empty answers are not stored so skip validation for them
if ($question['type'] === Constants::ANSWER_TYPE_SHORT
&& $answers[$questionId][0] !== ''
&& !$this->validateShortQuestion($question, $answers[$questionId][0])) {
throw new \InvalidArgumentException(sprintf('Invalid input for question "%s".', $question['text']));
}

Expand Down
24 changes: 24 additions & 0 deletions tests/Unit/Service/SubmissionServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,30 @@ public static function dataValidateSubmission() {
// Expected Result
'Invalid input for question "q1".',
],
'empty-short-email-not-required' => [
// Questions
[
['id' => 1, 'type' => 'short', 'text' => 'q1', 'isRequired' => false, 'extraSettings' => ['validationType' => 'email']]
],
// Answers
[
'1' => ['']
],
// Expected Result
null,
],
'empty-short-email-required' => [
// Questions
[
['id' => 1, 'type' => 'short', 'text' => 'q1', 'isRequired' => true, 'extraSettings' => ['validationType' => 'email']]
],
// Answers
[
'1' => ['']
],
// Expected Result
'Question "q1" is required.',
],
'invalid-short-regex-not-matching' => [
// Questions
[
Expand Down
Loading