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 +48
-9
lines changed Expand file tree Collapse file tree 3 files changed +48
-9
lines changed Original file line number Diff line number Diff line change 22
33namespace ProtoneMedia \LaravelFormComponents \Components ;
44
5+ use Illuminate \Support \Arr ;
6+
57class FormSelect extends Component
68{
79 use HandlesValidationErrors;
@@ -47,14 +49,6 @@ public function isSelected($key): bool
4749 return false ;
4850 }
4951
50- if ($ this ->selectedKey === $ key ) {
51- return true ;
52- }
53-
54- if (is_array ($ this ->selectedKey ) && in_array ($ key , $ this ->selectedKey )) {
55- return true ;
56- }
57-
58- return false ;
52+ return in_array ($ key , Arr::wrap ($ this ->selectedKey ));
5953 }
6054}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace ProtoneMedia \LaravelFormComponents \Tests \Feature ;
4+
5+ use Illuminate \Http \Request ;
6+ use ProtoneMedia \LaravelFormComponents \Tests \TestCase ;
7+
8+ class SelectWithoutKeysTest extends TestCase
9+ {
10+ /** @test */
11+ public function it_makes_the_values_numeric ()
12+ {
13+ $ this ->registerTestRoute ('select-without-keys ' , function (Request $ request ) {
14+ $ request ->validate ([
15+ 'select ' => 'required|in:a,b ' ,
16+ ]);
17+ });
18+
19+ $ this ->visit ('/select-without-keys ' )
20+ ->seeInElement ('option[value="0"] ' , 'a ' )
21+ ->seeInElement ('option[value="1"] ' , 'b ' )
22+ ->seeInElement ('option[value="2"] ' , 'c ' );
23+ }
24+
25+ /** @test */
26+ public function it_shows_a_validation_error ()
27+ {
28+ $ this ->registerTestRoute ('select-without-keys ' , function (Request $ request ) {
29+ $ request ->validate ([
30+ 'select ' => 'required|in:0,1 ' ,
31+ ]);
32+ });
33+
34+ $ this ->visit ('/select-without-keys ' )
35+ ->select ('2 ' , 'select ' )
36+ ->press ('Submit ' )
37+ ->seeElement ('option[value="0"]:not(:selected) ' )
38+ ->seeElement ('option[value="1"]:not(:selected) ' )
39+ ->seeElement ('option[value="2"]:selected ' );
40+ }
41+ }
Original file line number Diff line number Diff line change 1+ <x-form >
2+ <x-form-select name =" select" :options =" ['a', 'b', 'c']" />
3+ <x-form-submit />
4+ </x-form >
You can’t perform that action at this time.
0 commit comments