Skip to content

Commit

Permalink
fix #2744 バリデーションエラーを表示する (#2754)
Browse files Browse the repository at this point in the history
Co-authored-by: Nghiem <[email protected]>
  • Loading branch information
nghiem-mb and nghiemnv1205 authored Sep 26, 2023
1 parent 690c256 commit fb9f8f3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
16 changes: 16 additions & 0 deletions plugins/baser-core/src/Model/Validation/BcValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,4 +583,20 @@ public static function reserved($value): bool
return true;
}

/**
* 選択リストに同じ項目を複数登録するかをチェック
*
* @param $value
* @return bool
* @checked
* @notodo
* @unitTest
*/
public static function checkSelectList($value): bool
{
$data = preg_split("/\r\n|\n|\r/", $value);
$result = max(array_count_values($data));
return ($result < 2);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -584,4 +584,20 @@ public function testCheckHiragana()
$this->assertEquals($result, false);
}

/**
* test checkSelectList
*/
public function test_checkSelectList()
{
//戻り=falseケース
$str = "\r\r\n\n\ntest";
$result = $this->BcValidation->checkSelectList($str);
$this->assertFalse($result);
//戻り=trueケース
$str = "あa\n\n";
$result = $this->BcValidation->checkSelectList($str);
$this->assertTrue($result);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ public function validationDefault(Validator $validator): Validator
$validator
->scalar('type')
->notEmptyString('type', __d('baser_core', 'タイプを入力してください。'));
$validator
->add('source', [
'checkSelectList' => [
'provider' => 'bc',
'rule' => ['checkSelectList'],
'message' => __d('baser_core', '選択リストに同じ項目を複数登録できません。')
]
]);
return $validator;
}

Expand Down

0 comments on commit fb9f8f3

Please sign in to comment.