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 2
2
3
3
namespace ProtoneMedia \LaravelFormComponents \Components ;
4
4
5
+ use Illuminate \Support \Arr ;
6
+
5
7
class FormSelect extends Component
6
8
{
7
9
use HandlesValidationErrors;
@@ -47,14 +49,6 @@ public function isSelected($key): bool
47
49
return false ;
48
50
}
49
51
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 ));
59
53
}
60
54
}
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