Skip to content

Commit bc459f0

Browse files
committed
wip
1 parent 85b76e9 commit bc459f0

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/Fields/Checkbox.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function size(int $value): static
3232
*/
3333
public function newOption(mixed $value, string $label): Option
3434
{
35-
return parent::newOption($value, $label)
35+
return (new CheckboxOption($value, $label))
3636
->class('form-check__control')
3737
->setAttributes([
3838
'type' => 'checkbox',

src/Fields/CheckboxOption.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cone\Root\Fields;
6+
7+
class CheckboxOption extends Option
8+
{
9+
/**
10+
* Set the "selected" HTML attribute.
11+
*/
12+
public function selected(bool $value = true): static
13+
{
14+
return $this->checked($value);
15+
}
16+
17+
/**
18+
* Set the "selected" HTML attribute.
19+
*/
20+
public function checked(bool $value = true): static
21+
{
22+
return $this->setAttribute('checked', $value);
23+
}
24+
25+
/**
26+
* Get the array representation of the object.
27+
*/
28+
public function toArray(): array
29+
{
30+
$value = parent::toArray();
31+
32+
unset($value['selected']);
33+
34+
return array_merge($value, ['checked' => $this->getAttribute('checked')]);
35+
}
36+
}

0 commit comments

Comments
 (0)