This repository was archived by the owner on Jan 2, 2024. It is now read-only.
File tree 6 files changed +47
-6
lines changed 6 files changed +47
-6
lines changed Original file line number Diff line number Diff line change @@ -34,9 +34,9 @@ public function __construct(
34
34
$ this ->value = $ value ;
35
35
$ this ->showErrors = $ showErrors ;
36
36
37
- $ inputName = Str::before ($ name , '[] ' );
37
+ $ inputName = static :: convertBracketsToDots ( Str::before ($ name , '[] ' ) );
38
38
39
- if ($ oldData = old (static :: convertBracketsToDots ( $ inputName) )) {
39
+ if ($ oldData = old ($ inputName )) {
40
40
$ this ->checked = in_array ($ value , Arr::wrap ($ oldData ));
41
41
}
42
42
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ public function __construct(
32
32
}
33
33
34
34
if (!session ()->hasOldInput () && $ this ->isNotWired ()) {
35
- $ boundValue = $ this ->getBoundValue ($ bind , $ name );
35
+ $ boundValue = $ this ->getBoundValue ($ bind , $ inputName );
36
36
37
37
if (!is_null ($ boundValue )) {
38
38
$ this ->checked = $ boundValue == $ this ->value ;
Original file line number Diff line number Diff line change @@ -43,11 +43,11 @@ public function __construct(
43
43
$ this ->placeholder = $ placeholder ;
44
44
45
45
if ($ this ->isNotWired ()) {
46
- $ inputName = Str::before ($ name , '[] ' );
46
+ $ inputName = static :: convertBracketsToDots ( Str::before ($ name , '[] ' ) );
47
47
48
48
$ default = $ this ->getBoundValue ($ bind , $ inputName ) ?: $ default ;
49
49
50
- $ this ->selectedKey = old (static :: convertBracketsToDots ( $ inputName) , $ default );
50
+ $ this ->selectedKey = old ($ inputName , $ default );
51
51
52
52
if ($ this ->selectedKey instanceof Arrayable) {
53
53
$ this ->selectedKey = $ this ->selectedKey ->toArray ();
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ private function setValue(
19
19
$ inputName = static ::convertBracketsToDots ($ name );
20
20
21
21
if (!$ language ) {
22
- $ boundValue = $ this ->getBoundValue ($ bind , $ name );
22
+ $ boundValue = $ this ->getBoundValue ($ bind , $ inputName );
23
23
24
24
$ default = is_null ($ boundValue ) ? $ default : $ boundValue ;
25
25
Original file line number Diff line number Diff line change @@ -103,6 +103,21 @@ public function it_overrides_the_default_value()
103
103
->dontSeeElement ('input[name="radio"]:checked ' );
104
104
}
105
105
106
+ /** @test */
107
+ public function it_overrides_the_default_value_when_nested ()
108
+ {
109
+ $ this ->registerTestRoute ('default-values-with-nested-bound-target ' );
110
+
111
+ $ this ->visit ('/default-values-with-nested-bound-target ' )
112
+ ->seeElement ('input[name="nested[input]"][value="a"] ' )
113
+ ->seeInElement ('textarea[name="nested[textarea]"] ' , 'b ' )
114
+ ->seeElement ('select[name="nested[select]"] > option[value="c"]:selected ' )
115
+ ->seeElement ('input[name="nested[checkbox]"] ' )
116
+ ->dontSeeElement ('input[name="nested[checkbox]"]:checked ' )
117
+ ->seeElement ('input[name="nested[radio]"] ' )
118
+ ->dontSeeElement ('input[name="nested[radio]"]:checked ' );
119
+ }
120
+
106
121
/** @test */
107
122
public function it_can_bind_two_targets_to_the_form ()
108
123
{
Original file line number Diff line number Diff line change
1
+ @php
2
+ $target = [
3
+ ' nested' => [
4
+ ' input' => ' a' ,
5
+ ' textarea' => ' b' ,
6
+ ' select' => ' c' ,
7
+ ' checkbox' => false ,
8
+ ' radio' => false ,
9
+ ]
10
+ ];
11
+ @endphp
12
+
13
+ <x-form >
14
+ @bind ($target )
15
+ <x-form-input default =" d" name =" nested[input]" />
16
+ <x-form-textarea default =" e" name =" nested[textarea]" />
17
+ <x-form-select default =" f" name =" nested[select]" :options =" ['' => '', 'c' => 'c']" />
18
+ <x-form-checkbox :default =" true" name =" nested[checkbox]" />
19
+
20
+ <x-form-group name =" radio" >
21
+ <x-form-radio :default =" true" name =" nested[radio]" />
22
+ </x-form-group >
23
+
24
+ <x-form-submit />
25
+ @endbind
26
+ </x-form >
You can’t perform that action at this time.
0 commit comments