Skip to content
This repository was archived by the owner on Oct 20, 2025. It is now read-only.

Commit b80e9d6

Browse files
committed
Support for nested numeric input names
1 parent 74dce4e commit b80e9d6

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

app/app/Http/Controllers/FormComponentsController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public function defaultPhp()
3535
return view('form.components.defaultPhp');
3636
}
3737

38+
public function arrays()
39+
{
40+
return view('form.components.arrays');
41+
}
42+
3843
public function defaults()
3944
{
4045
Select::defaultChoices();
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
@extends('layout')
2+
3+
@section('content')
4+
5+
FormComponents
6+
7+
<div class="max-w-sm mx-auto px-4">
8+
<x-splade-form
9+
class="space-y-4"
10+
:default="[
11+
'options' => [],
12+
'nested' => ['key' => 'value', 'another' => 'key'],
13+
'list' => [1 => 'one', 2 => 'two', 3 => 'three'],
14+
'another' => [1 => 'one', 2 => 'two', 3 => 'three']
15+
]"
16+
>
17+
<x-splade-group name="options" inline>
18+
<x-splade-checkbox name="options[]" value="1" label="Option 1" />
19+
<x-splade-checkbox name="options[]" value="2" label="Option 2" />
20+
<x-splade-checkbox name="options[]" value="3" label="Option 3" />
21+
</x-splade-group>
22+
23+
<x-splade-input name="nested.key" />
24+
<x-splade-input name="nested[another]" />
25+
26+
<x-splade-input name="list[1]" />
27+
<x-splade-input name="list[2]" />
28+
<x-splade-input name="list[3]" />
29+
30+
<x-splade-input name="another.1" />
31+
<x-splade-input name="another.2" />
32+
<x-splade-input name="another.3" />
33+
34+
<x-splade-submit />
35+
36+
<div id="all">@{{ form.$all }}</div>
37+
</x-splade-form>
38+
</div>
39+
40+
@endsection

app/routes/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
Route::get('form/components/defaults', [FormComponentsController::class, 'defaults'])->name('form.components.defaults');
8282
Route::get('form/components/defaultJson', [FormComponentsController::class, 'defaultJson'])->name('form.components.defaultJson');
8383
Route::get('form/components/defaultPhp', [FormComponentsController::class, 'defaultPhp'])->name('form.components.defaultPhp');
84+
Route::get('form/components/arrays', [FormComponentsController::class, 'arrays'])->name('form.components.arrays');
8485
Route::get('form/components/eloquent', [FormComponentsController::class, 'eloquent'])->name('form.components.eloquent');
8586
Route::get('form/components/fluent', [FormComponentsController::class, 'fluent'])->name('form.components.fluent');
8687
Route::get('form/components/unguarded', [FormComponentsController::class, 'unguarded'])->name('form.components.unguarded');

src/Components/Form/InteractsWithFormElement.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,19 @@ public static function dottedName(string $name): string
2727

2828
public function formKey(): string
2929
{
30-
return static::dottedName($this->name);
30+
return collect(explode('.', static::dottedName($this->name)))
31+
->map(function (string $segment, int $index) {
32+
if ($index === 0) {
33+
return $segment;
34+
}
35+
36+
if (is_numeric($segment)) {
37+
return "[{$segment}]";
38+
}
39+
40+
return ".{$segment}";
41+
})
42+
->implode('');
3143
}
3244

3345
public function vueModel(): string

0 commit comments

Comments
 (0)