Skip to content

Commit

Permalink
Merge pull request #48 from systopia/fix-boolean-rules
Browse files Browse the repository at this point in the history
Fix boolean rules when used with select/radios instead of checkbox
  • Loading branch information
dontub authored Mar 13, 2024
2 parents adad02a + 07d1ada commit 0ef2c11
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Form/Control/Rule/StatesBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ private function getStates(string $effect, bool $negate): array {
*/
private function buildCondition($value): array {
if (is_bool($value)) {
return ['checked' => $value];
return [
['checked' => $value],
'and',
['value' => (int) $value],
];
}

if (NULL === $value) {
Expand Down
6 changes: 5 additions & 1 deletion tests/src/Unit/Form/Rule/StatesArrayFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ public function testProperties(): void {
[
'enabled' => [
'[name="foo[bar][baz]"]' => [
['checked' => FALSE],
[
['checked' => FALSE],
'and',
['value' => 0],
],
],
],
],
Expand Down

0 comments on commit 0ef2c11

Please sign in to comment.