This repository was archived by the owner on Jan 2, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +47
-6
lines changed Expand file tree Collapse file tree 6 files changed +47
-6
lines changed Original file line number Diff line number Diff line change @@ -34,9 +34,9 @@ public function __construct(
3434 $ this ->value = $ value ;
3535 $ this ->showErrors = $ showErrors ;
3636
37- $ inputName = Str::before ($ name , '[] ' );
37+ $ inputName = static :: convertBracketsToDots ( Str::before ($ name , '[] ' ) );
3838
39- if ($ oldData = old (static :: convertBracketsToDots ( $ inputName) )) {
39+ if ($ oldData = old ($ inputName )) {
4040 $ this ->checked = in_array ($ value , Arr::wrap ($ oldData ));
4141 }
4242
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ public function __construct(
3232 }
3333
3434 if (!session ()->hasOldInput () && $ this ->isNotWired ()) {
35- $ boundValue = $ this ->getBoundValue ($ bind , $ name );
35+ $ boundValue = $ this ->getBoundValue ($ bind , $ inputName );
3636
3737 if (!is_null ($ boundValue )) {
3838 $ this ->checked = $ boundValue == $ this ->value ;
Original file line number Diff line number Diff line change @@ -43,11 +43,11 @@ public function __construct(
4343 $ this ->placeholder = $ placeholder ;
4444
4545 if ($ this ->isNotWired ()) {
46- $ inputName = Str::before ($ name , '[] ' );
46+ $ inputName = static :: convertBracketsToDots ( Str::before ($ name , '[] ' ) );
4747
4848 $ default = $ this ->getBoundValue ($ bind , $ inputName ) ?: $ default ;
4949
50- $ this ->selectedKey = old (static :: convertBracketsToDots ( $ inputName) , $ default );
50+ $ this ->selectedKey = old ($ inputName , $ default );
5151
5252 if ($ this ->selectedKey instanceof Arrayable) {
5353 $ this ->selectedKey = $ this ->selectedKey ->toArray ();
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ private function setValue(
1919 $ inputName = static ::convertBracketsToDots ($ name );
2020
2121 if (!$ language ) {
22- $ boundValue = $ this ->getBoundValue ($ bind , $ name );
22+ $ boundValue = $ this ->getBoundValue ($ bind , $ inputName );
2323
2424 $ default = is_null ($ boundValue ) ? $ default : $ boundValue ;
2525
Original file line number Diff line number Diff line change @@ -103,6 +103,21 @@ public function it_overrides_the_default_value()
103103 ->dontSeeElement ('input[name="radio"]:checked ' );
104104 }
105105
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+
106121 /** @test */
107122 public function it_can_bind_two_targets_to_the_form ()
108123 {
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