Skip to content

Commit e918304

Browse files
authored
Merge pull request #231 from NetCommons3/fix_numeric_empty
fix: 「テキスト型+必須ではない+数値型」の場合、未入力にしても数値を入力してくださいとエラーが出る。
2 parents e597213 + c24ca6c commit e918304

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ jobs:
3030
runs-on: ubuntu-latest
3131
strategy:
3232
matrix:
33-
php: [ '7.2', '7.3', '7.4' ]
34-
mysql: [ '5.7', '8.0' ]
33+
php: [ '7.4' ]
34+
mysql: [ '8.0' ]
3535

3636
env:
3737
NC3_BUILD_DIR: "/opt/nc3"

Model/Behavior/QuestionnaireAnswerTextBehavior.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function answerMaxLength($model, $data, $question, $max) {
6969
* @param array $question 回答データに対応する質問
7070
* @param array $allAnswers 入力された回答すべて
7171
* @return bool
72+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
7273
*/
7374
public function answerTextValidation($model, $data, $question, $allAnswers) {
7475
if (! in_array($question['question_type'], $this->_textValidateType)) {
@@ -77,7 +78,7 @@ public function answerTextValidation($model, $data, $question, $allAnswers) {
7778
$ret = true;
7879
// 数値型回答を望まれている場合
7980
if ($question['question_type_option'] == QuestionnairesComponent::TYPE_OPTION_NUMERIC) {
80-
if (!Validation::numeric($data['answer_value'])) {
81+
if (mb_strlen($data['answer_value']) !== 0 && !Validation::numeric($data['answer_value'])) {
8182
$ret = false;
8283
$model->validationErrors['answer_value'][] = __d('questionnaires', 'Number required');
8384
}
@@ -86,7 +87,7 @@ public function answerTextValidation($model, $data, $question, $allAnswers) {
8687
$data['answer_value'],
8788
intval($question['min']),
8889
intval($question['max']));
89-
if (!$rangeRes) {
90+
if (mb_strlen($data['answer_value']) !== 0 && !$rangeRes) {
9091
$ret = false;
9192
$model->validationErrors['answer_value'][] = __d('questionnaires',
9293
'Please enter the answer between %s and %s.',

0 commit comments

Comments
 (0)