From 8f86617f812e67063d993827aea99abd013dce31 Mon Sep 17 00:00:00 2001 From: Aselsan Date: Sun, 7 Jul 2024 11:35:10 +0700 Subject: [PATCH 01/21] add required_if rule --- system/Validation/Rules.php | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/system/Validation/Rules.php b/system/Validation/Rules.php index 06586a64190d..ab28b9dc9ba4 100644 --- a/system/Validation/Rules.php +++ b/system/Validation/Rules.php @@ -436,6 +436,47 @@ public function required_without( return true; } + /** + * This field is required when any of the other required fields have their expected values present + * in the data. + * + * Example (The special_option field is required when the normal_option,1,2 field has the given value.): + * + * required_if[normal_option,1,2] + * + * @param string|null $str + * @param string|null $fieldWithValue that we should check if present + * @param array $data Complete list of field from the form + */ + public function required_if($str = null, ?string $fieldWithValue = null, array $data = []): bool + { + if ($fieldWithValue === null || $data === []) { + throw new InvalidArgumentException('You must supply the parameters: field,expected_values, data.'); + } + + // Separate fields and expected values + $parts = explode(',', $fieldWithValue); + $field = array_shift($parts); // Get field + $expectedValues = $parts; // The remainder is the expected value + + if (trim($field) === '' || $expectedValues === []) { + throw new InvalidArgumentException('You must supply the expected values of field: E.g. field,value1,value2,...'); + } + + // If the field does not exist in the data, immediately return true + if (! array_key_exists($field, $data)) { + return true; + } + + // If the value of a field matches one of the expected values, then this field is required + if (in_array($data[$field], $expectedValues, true)) { + // The field to be checked must exist and cannot be empty + return trim($str) !== ''; + } + + return true; + } + /** * The field exists in $data. * From 195bacfb82ac2bf86d96340d2c4bbb3cda7a54ff Mon Sep 17 00:00:00 2001 From: Aselsan Date: Sun, 7 Jul 2024 11:37:16 +0700 Subject: [PATCH 02/21] add required_if strict rule --- system/Validation/StrictRules/Rules.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/system/Validation/StrictRules/Rules.php b/system/Validation/StrictRules/Rules.php index e4fc4fc91142..6c79b6021aa6 100644 --- a/system/Validation/StrictRules/Rules.php +++ b/system/Validation/StrictRules/Rules.php @@ -407,6 +407,23 @@ public function required_without( return $this->nonStrictRules->required_without($str, $otherFields, $data, $error, $field); } + /** + * This field is required when any of the other required fields have their expected values present + * in the data. + * + * Example (The special_option field is required when the normal_option,1,2 field has the given value.): + * + * required_if[normal_option,1,2] + * + * @param string|null $str + * @param string|null $fieldWithValue that we should check if present + * @param array $data Complete list of field from the form + */ + public function required_if($str = null, ?string $fieldWithValue = null, array $data = []): bool + { + return $this->nonStrictRules->required_if($str, $fieldWithValue, $data); + } + /** * The field exists in $data. * From 82954bf0c1bf6beac3e986ead76358f071384745 Mon Sep 17 00:00:00 2001 From: Aselsan Date: Sun, 7 Jul 2024 11:40:14 +0700 Subject: [PATCH 03/21] adjust processPermitEmpty to work with the required_if rule --- system/Validation/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php index 30245811e583..fd9487a1c144 100644 --- a/system/Validation/Validation.php +++ b/system/Validation/Validation.php @@ -436,7 +436,7 @@ private function processPermitEmpty($value, array $rules, array $data) $rule = $match[1]; $param = $match[2]; - if (! in_array($rule, ['required_with', 'required_without'], true)) { + if (! in_array($rule, ['required_with', 'required_without', 'required_if'], true)) { continue; } From 20f3b4b8d61a6916b59217e7fb88b634b7d8b72a Mon Sep 17 00:00:00 2001 From: Aselsan Date: Sun, 7 Jul 2024 11:41:33 +0700 Subject: [PATCH 04/21] add translation for required_if rule --- system/Language/en/Validation.php | 1 + 1 file changed, 1 insertion(+) diff --git a/system/Language/en/Validation.php b/system/Language/en/Validation.php index facf512d559a..9d0197c2b3b0 100644 --- a/system/Language/en/Validation.php +++ b/system/Language/en/Validation.php @@ -53,6 +53,7 @@ 'required' => 'The {field} field is required.', 'required_with' => 'The {field} field is required when {param} is present.', 'required_without' => 'The {field} field is required when {param} is not present.', + 'required_if' => 'The {field} field is required when the {param} field has the given value.', 'string' => 'The {field} field must be a valid string.', 'timezone' => 'The {field} field must be a valid timezone.', 'valid_base64' => 'The {field} field must be a valid base64 string.', From 62737f187071e72cce4694a84bcfb0026191213e Mon Sep 17 00:00:00 2001 From: Aselsan Date: Sun, 7 Jul 2024 11:56:12 +0700 Subject: [PATCH 05/21] docs: add changelog --- user_guide_src/source/changelogs/v4.6.0.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/user_guide_src/source/changelogs/v4.6.0.rst b/user_guide_src/source/changelogs/v4.6.0.rst index e675b871a9c3..ffc2d5907beb 100644 --- a/user_guide_src/source/changelogs/v4.6.0.rst +++ b/user_guide_src/source/changelogs/v4.6.0.rst @@ -146,8 +146,9 @@ Libraries - **FileCollection:** Added ``retainMultiplePatterns()`` to ``FileCollection`` class. See :ref:`FileCollection::retainMultiplePatterns() `. -- **Validation:** Added ``min_dims`` validation rule to ``FileRules`` class. See - :ref:`Validation `. +- **Validation:** + - Added ``min_dims`` validation rule to ``FileRules`` class. See :ref:`Validation `. + - Added ``required_if`` validation rule to ``Rules`` class. See :ref:`Validation `. Helpers and Functions ===================== @@ -165,6 +166,7 @@ Message Changes *************** - Added ``Validation.min_dims`` message +- Added ``Validation.required_if`` message ******* Changes From db6d923c1969a6c7787ed6eb5e50148ff4a76ca7 Mon Sep 17 00:00:00 2001 From: Aselsan Date: Sun, 7 Jul 2024 12:12:33 +0700 Subject: [PATCH 06/21] docs: add required_if to rules for general use table --- user_guide_src/source/libraries/validation.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/libraries/validation.rst b/user_guide_src/source/libraries/validation.rst index 940207bed4a6..63d222144acb 100644 --- a/user_guide_src/source/libraries/validation.rst +++ b/user_guide_src/source/libraries/validation.rst @@ -972,10 +972,13 @@ regex_match Yes Fails if field does not match the regular expression. required No Fails if the field is an empty array, empty string, null or false. +required_if Yes The field is required when any of the other ``required_if[field,value1,value2,...]`` + field has the given value. (This rule was + added in v4.6.0.) required_with Yes The field is required when any of the other ``required_with[field1,field2]`` fields is not `empty()`_ in the data. required_without Yes The field is required when any of the other ``required_without[field1,field2]`` - fields is `empty()`_ in the data. + fields is `empty()`_ in the data. string No A generic alternative to the **alpha*** rules that confirms the element is a string timezone No Fails if field does not match a timezone From 140700601306e366ffdde1c8aea6ee1a6fd72f39 Mon Sep 17 00:00:00 2001 From: Aselsan Date: Sun, 7 Jul 2024 12:46:47 +0700 Subject: [PATCH 07/21] remove whitespace --- system/Validation/Rules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Validation/Rules.php b/system/Validation/Rules.php index ab28b9dc9ba4..85624f4211f3 100644 --- a/system/Validation/Rules.php +++ b/system/Validation/Rules.php @@ -437,7 +437,7 @@ public function required_without( } /** - * This field is required when any of the other required fields have their expected values present + * This field is required when any of the other required fields have their expected values present * in the data. * * Example (The special_option field is required when the normal_option,1,2 field has the given value.): From de666cc13b0fa0ac5ce3a9f59559daaaa0604874 Mon Sep 17 00:00:00 2001 From: Aselsan Date: Sun, 7 Jul 2024 12:47:26 +0700 Subject: [PATCH 08/21] remove whitespace --- system/Validation/StrictRules/Rules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Validation/StrictRules/Rules.php b/system/Validation/StrictRules/Rules.php index 6c79b6021aa6..c4916bf95b78 100644 --- a/system/Validation/StrictRules/Rules.php +++ b/system/Validation/StrictRules/Rules.php @@ -408,7 +408,7 @@ public function required_without( } /** - * This field is required when any of the other required fields have their expected values present + * This field is required when any of the other required fields have their expected values present * in the data. * * Example (The special_option field is required when the normal_option,1,2 field has the given value.): From 95bf9b5ccf6c9be3d9ae5fc19c67fa6afb97bca4 Mon Sep 17 00:00:00 2001 From: Aselsan Date: Sun, 7 Jul 2024 14:01:06 +0700 Subject: [PATCH 09/21] test: add test cases --- tests/system/Validation/RulesTest.php | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/system/Validation/RulesTest.php b/tests/system/Validation/RulesTest.php index 7c69fa24838e..b1d95510d31e 100644 --- a/tests/system/Validation/RulesTest.php +++ b/tests/system/Validation/RulesTest.php @@ -923,4 +923,34 @@ public function testFieldExistsErrorMessage(): void $this->validation->getErrors() ); } + + #[DataProvider('provideRequiredIf')] + public function testRequiredIf(bool $expected, array $data): void + { + $this->validation->setRules([ + 'special_option' => 'required_if[normal_option,1,2]', + ]); + + $result = $this->validation->run($data); + + $this->assertSame($expected, $result); + } + + public static function provideRequiredIf(): iterable + { + yield from [ + // `normal_option` and `special_option` do not exist + [true, []], + // `special_option` is not required because `normal_option` field does not have expected value + [true, ['normal_option' => '', 'special_option' => '']], + [true, ['normal_option' => '0', 'special_option' => '']], + [true, ['normal_option' => null, 'special_option' => '']], + // `special_option` is required and exist + [false, ['normal_option' => '1', 'special_option' => '']], + [false, ['normal_option' => '2', 'special_option' => '']], + // `special_option` is required but do not exist + [false, ['normal_option' => '1']], + [false, ['normal_option' => '2']], + ]; + } } From 8cde4a0739cc3ff1770e5c374a3b1e12c7e1ebfc Mon Sep 17 00:00:00 2001 From: Aselsan Date: Sun, 7 Jul 2024 14:26:55 +0700 Subject: [PATCH 10/21] test: add test cases with other rules --- tests/system/Validation/RulesTest.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/system/Validation/RulesTest.php b/tests/system/Validation/RulesTest.php index b1d95510d31e..f87a204ab811 100644 --- a/tests/system/Validation/RulesTest.php +++ b/tests/system/Validation/RulesTest.php @@ -953,4 +953,29 @@ public static function provideRequiredIf(): iterable [false, ['normal_option' => '2']], ]; } + + #[DataProvider('provideRequiredIfWorkWithOtherRule')] + public function testRequiredIfWorkWithOtherRule(bool $expected, array $data): void + { + $this->validation->setRules([ + 'special_option' => 'required_if[normal_option,1,2]|permit_empty|integer', + ]); + + $result = $this->validation->run($data); + + $this->assertSame($expected, $result); + } + + public static function provideRequiredIfWorkWithOtherRule(): iterable + { + yield from [ + // `special_option` with integer value + [true, ['normal_option' => '1', 'special_option' => '1']], + [true, ['normal_option' => '2', 'special_option' => '1']], + // `special_option` is not empty, but it is not contain an integer + // value, which triggers the Validation.integer error message. + [false, ['normal_option' => '1', 'special_option' => 'lorem ipsum']], + [false, ['normal_option' => '2', 'special_option' => 'lorem sit amet']], + ]; + } } From 58659716dc7a19ee78472a0643ede0fe990db6da Mon Sep 17 00:00:00 2001 From: Aselsan Date: Sun, 7 Jul 2024 14:28:40 +0700 Subject: [PATCH 11/21] update comment --- tests/system/Validation/RulesTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/Validation/RulesTest.php b/tests/system/Validation/RulesTest.php index f87a204ab811..427dc04dd664 100644 --- a/tests/system/Validation/RulesTest.php +++ b/tests/system/Validation/RulesTest.php @@ -972,7 +972,7 @@ public static function provideRequiredIfWorkWithOtherRule(): iterable // `special_option` with integer value [true, ['normal_option' => '1', 'special_option' => '1']], [true, ['normal_option' => '2', 'special_option' => '1']], - // `special_option` is not empty, but it is not contain an integer + // `special_option` is not empty, but it is not an integer // value, which triggers the Validation.integer error message. [false, ['normal_option' => '1', 'special_option' => 'lorem ipsum']], [false, ['normal_option' => '2', 'special_option' => 'lorem sit amet']], From 6e7f7cf887a5a086dd32d631f30b4e98364aecbc Mon Sep 17 00:00:00 2001 From: Aselsan Date: Sun, 7 Jul 2024 17:11:17 +0700 Subject: [PATCH 12/21] remove whitespace by PHP CS Fixer --- tests/system/Validation/RulesTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/Validation/RulesTest.php b/tests/system/Validation/RulesTest.php index 427dc04dd664..b5773e6ed17c 100644 --- a/tests/system/Validation/RulesTest.php +++ b/tests/system/Validation/RulesTest.php @@ -969,7 +969,7 @@ public function testRequiredIfWorkWithOtherRule(bool $expected, array $data): vo public static function provideRequiredIfWorkWithOtherRule(): iterable { yield from [ - // `special_option` with integer value + // `special_option` with integer value [true, ['normal_option' => '1', 'special_option' => '1']], [true, ['normal_option' => '2', 'special_option' => '1']], // `special_option` is not empty, but it is not an integer From e127ddd161ecc7a3bc3bc175c2b45f2e234987dd Mon Sep 17 00:00:00 2001 From: Aselsan Date: Tue, 9 Jul 2024 03:23:09 +0700 Subject: [PATCH 13/21] fix: TypeError in strict mode, string dataType required but null given --- system/Validation/Rules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Validation/Rules.php b/system/Validation/Rules.php index 85624f4211f3..b02920e3a997 100644 --- a/system/Validation/Rules.php +++ b/system/Validation/Rules.php @@ -471,7 +471,7 @@ public function required_if($str = null, ?string $fieldWithValue = null, array $ // If the value of a field matches one of the expected values, then this field is required if (in_array($data[$field], $expectedValues, true)) { // The field to be checked must exist and cannot be empty - return trim($str) !== ''; + return trim($str ?? '') !== ''; } return true; From c5c9578fcf584d629e9aeffa86941f28be8d7570 Mon Sep 17 00:00:00 2001 From: Aselsan Date: Tue, 9 Jul 2024 03:41:31 +0700 Subject: [PATCH 14/21] fix: parameter $data with no value type specified in iterable type array. --- tests/system/Validation/RulesTest.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/system/Validation/RulesTest.php b/tests/system/Validation/RulesTest.php index b5773e6ed17c..fcc609c3c17c 100644 --- a/tests/system/Validation/RulesTest.php +++ b/tests/system/Validation/RulesTest.php @@ -924,6 +924,9 @@ public function testFieldExistsErrorMessage(): void ); } + /** + * @param array $data + */ #[DataProvider('provideRequiredIf')] public function testRequiredIf(bool $expected, array $data): void { @@ -954,6 +957,9 @@ public static function provideRequiredIf(): iterable ]; } + /** + * @param array $data + */ #[DataProvider('provideRequiredIfWorkWithOtherRule')] public function testRequiredIfWorkWithOtherRule(bool $expected, array $data): void { @@ -974,8 +980,8 @@ public static function provideRequiredIfWorkWithOtherRule(): iterable [true, ['normal_option' => '2', 'special_option' => '1']], // `special_option` is not empty, but it is not an integer // value, which triggers the Validation.integer error message. - [false, ['normal_option' => '1', 'special_option' => 'lorem ipsum']], - [false, ['normal_option' => '2', 'special_option' => 'lorem sit amet']], + [false, ['normal_option' => '1', 'special_option' => 'a']], + [false, ['normal_option' => '2', 'special_option' => 'b']], ]; } } From 6980b323d664ae6be10f139fff047ac47a117c44 Mon Sep 17 00:00:00 2001 From: Aselsan Date: Tue, 9 Jul 2024 14:02:44 +0700 Subject: [PATCH 15/21] fix: return type has no value type specified in iterable type iterable. --- tests/system/Validation/RulesTest.php | 45 ++++++++++++++------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/tests/system/Validation/RulesTest.php b/tests/system/Validation/RulesTest.php index fcc609c3c17c..e3314156b07f 100644 --- a/tests/system/Validation/RulesTest.php +++ b/tests/system/Validation/RulesTest.php @@ -931,7 +931,8 @@ public function testFieldExistsErrorMessage(): void public function testRequiredIf(bool $expected, array $data): void { $this->validation->setRules([ - 'special_option' => 'required_if[normal_option,1,2]', + 'is_internal' => 'in_list[0,1,2,3]|permit_empty', + 'identity_number' => 'required_if[is_internal,1,2]', ]); $result = $this->validation->run($data); @@ -939,21 +940,22 @@ public function testRequiredIf(bool $expected, array $data): void $this->assertSame($expected, $result); } - public static function provideRequiredIf(): iterable + public static function provideRequiredIf(): \Generator { yield from [ - // `normal_option` and `special_option` do not exist + // `is_internal` and `identity_number` do not exist [true, []], - // `special_option` is not required because `normal_option` field does not have expected value - [true, ['normal_option' => '', 'special_option' => '']], - [true, ['normal_option' => '0', 'special_option' => '']], - [true, ['normal_option' => null, 'special_option' => '']], - // `special_option` is required and exist - [false, ['normal_option' => '1', 'special_option' => '']], - [false, ['normal_option' => '2', 'special_option' => '']], - // `special_option` is required but do not exist - [false, ['normal_option' => '1']], - [false, ['normal_option' => '2']], + // `identity_number` is not required because field `is_internal` + // value does not match with any value in the rule params + [true, ['is_internal' => '', 'identity_number' => '']], + [true, ['is_internal' => '0', 'identity_number' => '']], + [true, ['is_internal' => '3', 'identity_number' => '']], + // `identity_number` is required and exist + [false, ['is_internal' => '1', 'identity_number' => '']], + [false, ['is_internal' => '2', 'identity_number' => '']], + // `identity_number` is required but do not exist + [false, ['is_internal' => '1']], + [false, ['is_internal' => '2']], ]; } @@ -964,7 +966,8 @@ public static function provideRequiredIf(): iterable public function testRequiredIfWorkWithOtherRule(bool $expected, array $data): void { $this->validation->setRules([ - 'special_option' => 'required_if[normal_option,1,2]|permit_empty|integer', + 'is_internal' => 'in_list[0,1,2,3]|permit_empty', + 'identity_number' => 'required_if[is_internal,1,2]|permit_empty|integer', ]); $result = $this->validation->run($data); @@ -972,16 +975,16 @@ public function testRequiredIfWorkWithOtherRule(bool $expected, array $data): vo $this->assertSame($expected, $result); } - public static function provideRequiredIfWorkWithOtherRule(): iterable + public static function provideRequiredIfWorkWithOtherRule(): \Generator { yield from [ - // `special_option` with integer value - [true, ['normal_option' => '1', 'special_option' => '1']], - [true, ['normal_option' => '2', 'special_option' => '1']], - // `special_option` is not empty, but it is not an integer + // `identity_number` with integer value + [true, ['is_internal' => '1', 'identity_number' => '3207783']], + [true, ['is_internal' => '2', 'identity_number' => '3207783']], + // `identity_number` is not empty, but it is not an integer // value, which triggers the Validation.integer error message. - [false, ['normal_option' => '1', 'special_option' => 'a']], - [false, ['normal_option' => '2', 'special_option' => 'b']], + [false, ['is_internal' => '1', 'identity_number' => 'a']], + [false, ['is_internal' => '2', 'identity_number' => 'b']], ]; } } From 1215f36ed01c434a265aaee3a64751a2d183c7e9 Mon Sep 17 00:00:00 2001 From: Aselsan Date: Tue, 9 Jul 2024 14:23:20 +0700 Subject: [PATCH 16/21] make Lint with PHP CS Fixer happy --- tests/system/Validation/RulesTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/system/Validation/RulesTest.php b/tests/system/Validation/RulesTest.php index e3314156b07f..9e6fce727d2d 100644 --- a/tests/system/Validation/RulesTest.php +++ b/tests/system/Validation/RulesTest.php @@ -940,12 +940,12 @@ public function testRequiredIf(bool $expected, array $data): void $this->assertSame($expected, $result); } - public static function provideRequiredIf(): \Generator + public static function provideRequiredIf(): Generator { yield from [ // `is_internal` and `identity_number` do not exist [true, []], - // `identity_number` is not required because field `is_internal` + // `identity_number` is not required because field `is_internal` // value does not match with any value in the rule params [true, ['is_internal' => '', 'identity_number' => '']], [true, ['is_internal' => '0', 'identity_number' => '']], @@ -975,7 +975,7 @@ public function testRequiredIfWorkWithOtherRule(bool $expected, array $data): vo $this->assertSame($expected, $result); } - public static function provideRequiredIfWorkWithOtherRule(): \Generator + public static function provideRequiredIfWorkWithOtherRule(): Generator { yield from [ // `identity_number` with integer value From 97eb7fe225d195181785e11514728be8aaa63f06 Mon Sep 17 00:00:00 2001 From: Aselsan Date: Tue, 9 Jul 2024 14:34:04 +0700 Subject: [PATCH 17/21] update: add missing Generator class --- tests/system/Validation/RulesTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/system/Validation/RulesTest.php b/tests/system/Validation/RulesTest.php index 9e6fce727d2d..f85f9d74d428 100644 --- a/tests/system/Validation/RulesTest.php +++ b/tests/system/Validation/RulesTest.php @@ -20,6 +20,7 @@ use PHPUnit\Framework\Attributes\Group; use stdClass; use Tests\Support\Validation\TestRules; +use Generator; /** * @internal From 4ef7b2ac002accc1edfa6e375ae55a9a1debb7c5 Mon Sep 17 00:00:00 2001 From: Aselsan Date: Tue, 9 Jul 2024 14:39:21 +0700 Subject: [PATCH 18/21] fix: Generator class order --- tests/system/Validation/RulesTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/Validation/RulesTest.php b/tests/system/Validation/RulesTest.php index f85f9d74d428..eb390ae17237 100644 --- a/tests/system/Validation/RulesTest.php +++ b/tests/system/Validation/RulesTest.php @@ -16,11 +16,11 @@ use CodeIgniter\Test\CIUnitTestCase; use Config\Services; use ErrorException; +use Generator; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Group; use stdClass; use Tests\Support\Validation\TestRules; -use Generator; /** * @internal From 08dd97513002758f95fcbce9d494b27deedb5cce Mon Sep 17 00:00:00 2001 From: Aselsan Date: Wed, 10 Jul 2024 10:05:23 +0700 Subject: [PATCH 19/21] add more test cases Co-authored-by: kenjis --- tests/system/Validation/RulesTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/system/Validation/RulesTest.php b/tests/system/Validation/RulesTest.php index eb390ae17237..4f5a26245301 100644 --- a/tests/system/Validation/RulesTest.php +++ b/tests/system/Validation/RulesTest.php @@ -954,9 +954,21 @@ public static function provideRequiredIf(): Generator // `identity_number` is required and exist [false, ['is_internal' => '1', 'identity_number' => '']], [false, ['is_internal' => '2', 'identity_number' => '']], + [true, ['is_internal' => '1', 'identity_number' => '123']], + [true, ['is_internal' => '2', 'identity_number' => '123']], // `identity_number` is required but do not exist [false, ['is_internal' => '1']], [false, ['is_internal' => '2']], + // `identity_number` with integer value + [true, ['is_internal' => '1', 'identity_number' => '3207783']], + [true, ['is_internal' => '2', 'identity_number' => '3207783']], + [true, ['identity_number' => '3207783']], + [true, ['identity_number' => '3207783']], + // `identity_number` with string value + [true, ['is_internal' => '1', 'identity_number' => 'a']], + [true, ['is_internal' => '2', 'identity_number' => 'b']], + [true, ['identity_number' => 'a']], + [true, ['identity_number' => 'b']], ]; } From afed8fbc57ab696c6ce613798bab1ea38afb3a88 Mon Sep 17 00:00:00 2001 From: Aselsan Date: Wed, 10 Jul 2024 10:13:48 +0700 Subject: [PATCH 20/21] docs: update description --- user_guide_src/source/libraries/validation.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/user_guide_src/source/libraries/validation.rst b/user_guide_src/source/libraries/validation.rst index 63d222144acb..61228cb649f0 100644 --- a/user_guide_src/source/libraries/validation.rst +++ b/user_guide_src/source/libraries/validation.rst @@ -972,13 +972,13 @@ regex_match Yes Fails if field does not match the regular expression. required No Fails if the field is an empty array, empty string, null or false. -required_if Yes The field is required when any of the other ``required_if[field,value1,value2,...]`` - field has the given value. (This rule was +required_if Yes The field is required when the other field ``required_if[field,value1,value2,...]`` + has the given values. (This rule was added in v4.6.0.) required_with Yes The field is required when any of the other ``required_with[field1,field2]`` fields is not `empty()`_ in the data. required_without Yes The field is required when any of the other ``required_without[field1,field2]`` - fields is `empty()`_ in the data. + fields is `empty()`_ in the data. string No A generic alternative to the **alpha*** rules that confirms the element is a string timezone No Fails if field does not match a timezone From a3056c5254f0ddf5271eba330d76540392290229 Mon Sep 17 00:00:00 2001 From: Aselsan Date: Mon, 22 Jul 2024 11:19:26 +0700 Subject: [PATCH 21/21] Update v4.6.0.rst --- user_guide_src/source/changelogs/v4.6.0.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/user_guide_src/source/changelogs/v4.6.0.rst b/user_guide_src/source/changelogs/v4.6.0.rst index ac37df8916ad..0872ba776bd8 100644 --- a/user_guide_src/source/changelogs/v4.6.0.rst +++ b/user_guide_src/source/changelogs/v4.6.0.rst @@ -170,7 +170,6 @@ Message Changes - Added ``Errors.badRequest`` and ``Errors.sorryBadRequest`` - Added ``Validation.required_if`` message - ******* Changes *******