This repository was archived by the owner on Jan 2, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace ProtoneMedia \LaravelFormComponents \Components ;
4
4
5
+ use Illuminate \Contracts \Support \Arrayable ;
5
6
use Illuminate \Support \Arr ;
6
7
use Illuminate \Support \Str ;
7
8
@@ -42,6 +43,10 @@ public function __construct(
42
43
if (!session ()->hasOldInput () && $ this ->isNotWired ()) {
43
44
$ boundValue = $ this ->getBoundValue ($ bind , $ inputName );
44
45
46
+ if ($ boundValue instanceof Arrayable) {
47
+ $ boundValue = $ boundValue ->toArray ();
48
+ }
49
+
45
50
if (is_array ($ boundValue )) {
46
51
$ this ->checked = in_array ($ value , $ boundValue );
47
52
return ;
Original file line number Diff line number Diff line change @@ -17,6 +17,16 @@ public function it_check_the_right_element_as_default()
17
17
->seeElement ('input[value="b"]:not(:checked) ' );
18
18
}
19
19
20
+ /** @test */
21
+ public function it_supports_bound_collections ()
22
+ {
23
+ $ this ->registerTestRoute ('checkbox-collection ' );
24
+
25
+ $ this ->visit ('/checkbox-collection ' )
26
+ ->seeElement ('input[value="read"]:checked ' )
27
+ ->seeElement ('input[value="write"]:not(:checked) ' );
28
+ }
29
+
20
30
/** @test */
21
31
public function it_does_check_the_right_input_element_after_a_validation_error ()
22
32
{
Original file line number Diff line number Diff line change
1
+ @php
2
+ $target = [' permissions' => collect ([' read' ])]
3
+ @endphp
4
+
5
+ <x-form >
6
+ @bind ($target )
7
+ <x-form-group >
8
+ <x-form-checkbox name =" permissions[]" value =" read" />
9
+ <x-form-checkbox name =" permissions[]" value =" write" />
10
+ </x-form-group >
11
+ @endbind
12
+
13
+ <x-form-submit />
14
+ </x-form >
You can’t perform that action at this time.
0 commit comments