Skip to content
Merged
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
12 changes: 12 additions & 0 deletions tests/system/Validation/ValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ public function testRulesSetup($rules, $expected, array $errors = [])
$data = ['foo' => ''];
$this->validation->setRules(['foo' => $rules], $errors);
$this->validation->run($data);

$this->assertSame($expected, $this->validation->getError('foo'));
}

Expand Down Expand Up @@ -468,13 +469,24 @@ public function rulesSetupProvider(): Generator
['rules' => 'min_length[10]'],
'The foo field must be at least 10 characters in length.',
],
[
['rules' => ['min_length[10]']],
'The foo field must be at least 10 characters in length.',
],
[
[
'label' => 'Foo Bar',
'rules' => 'min_length[10]',
],
'The Foo Bar field must be at least 10 characters in length.',
],
[
[
'label' => 'Foo Bar',
'rules' => ['min_length[10]'],
],
'The Foo Bar field must be at least 10 characters in length.',
],
[
[
'label' => 'Foo Bar',
Expand Down
5 changes: 5 additions & 0 deletions user_guide_src/source/libraries/validation/006.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@
'username' => 'required',
'password' => 'required|min_length[10]',
]);
// or
$validation->setRules([
'username' => 'required',
'password' => ['required', 'min_length[10]'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize we supported this format 😂 Good addition.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this format, probably we can use | in regex.

]);
5 changes: 5 additions & 0 deletions user_guide_src/source/libraries/validation/007.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@
'username' => ['label' => 'Username', 'rules' => 'required'],
'password' => ['label' => 'Password', 'rules' => 'required|min_length[10]'],
]);
// or
$validation->setRules([
'username' => ['label' => 'Username', 'rules' => 'required'],
'password' => ['label' => 'Password', 'rules' => ['required', 'min_length[10]']],
]);