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

Commit c108dd5

Browse files
committed
Form fixes + added additional test
1 parent 5b4f81b commit c108dd5

File tree

7 files changed

+79
-4
lines changed

7 files changed

+79
-4
lines changed

app/app/Http/Controllers/FormComponentsController.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,22 @@ public function libraryDefaults()
8787
]);
8888
}
8989

90+
public function libraryChange()
91+
{
92+
return view('form.components.libraryChange', [
93+
'defaults' => [
94+
'biography' => 'Voluptate ea culpa proident proident qui nostrud non ea irure ullamco in non reprehenderit.',
95+
'country' => 'NL',
96+
'countries' => ['BE', 'NL'],
97+
'date' => '2022-07-22',
98+
'time' => '13:37',
99+
'datetime' => '2022-07-22 13:37',
100+
'daterange' => '2022-07-22 to 2022-08-22',
101+
],
102+
'countries' => $this->countries(),
103+
]);
104+
}
105+
90106
public function custom()
91107
{
92108
return view('form.components.custom', ['countries' => $this->countries()]);
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+
:action="route('form.components.submit')"
11+
:default="$defaults"
12+
>
13+
<x-splade-textarea name="biography" placeholder="Your Bio" autosize />
14+
15+
<x-splade-select name="country" :options="$countries" placeholder="Select your country" choices />
16+
<p class="mb-4" v-if="form.country">Selected country: <span v-text="form.country"></span></p>
17+
18+
<x-splade-select name="countries[]" :options="$countries" placeholder="Select your countries" multiple choices />
19+
<p class="mb-4" v-if="form.countries.length">Selected countries: <span v-text="form.countries.join(', ')"></span></p>
20+
21+
<x-splade-input placeholder="Date" name="date" date />
22+
<x-splade-input placeholder="Time" name="time" time />
23+
<x-splade-input placeholder="Datetime" name="datetime" date time />
24+
<x-splade-input placeholder="Date Range" name="daterange" date range />
25+
26+
<x-splade-submit />
27+
28+
<button @click.prevent="
29+
form.biography = 'Changed!';
30+
form.country = 'BE';
31+
form.countries = ['DE', 'IT'];
32+
form.date = '2022-08-22';
33+
form.time = '3:14';
34+
form.datetime = '2022-08-22 3:14';
35+
form.daterange = '2022-08-22 to 2022-09-22';
36+
">Change!</button>
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
@@ -82,6 +82,7 @@
8282
Route::get('form/components/simple', [FormComponentsController::class, 'simple'])->name('form.components.simple');
8383
Route::get('form/components/libraries', [FormComponentsController::class, 'libraries'])->name('form.components.libraries');
8484
Route::get('form/components/libraryDefaults', [FormComponentsController::class, 'libraryDefaults'])->name('form.components.libraryDefaults');
85+
Route::get('form/components/libraryChange', [FormComponentsController::class, 'libraryChange'])->name('form.components.libraryChange');
8586
Route::get('form/components/custom', [FormComponentsController::class, 'custom'])->name('form.components.custom');
8687
Route::get('form/components/defaults', [FormComponentsController::class, 'defaults'])->name('form.components.defaults');
8788
Route::get('form/components/defaultJson', [FormComponentsController::class, 'defaultJson'])->name('form.components.defaultJson');

app/tests/Browser/Form/LibrariesTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class LibrariesTest extends DuskTestCase
1010
{
1111
/** @test */
12-
public function it_select_the_default_values()
12+
public function it_selects_the_default_values()
1313
{
1414
$this->browse(function (Browser $browser) {
1515
$browser->visit('form/components/libraryDefaults')
@@ -25,6 +25,24 @@ public function it_select_the_default_values()
2525
});
2626
}
2727

28+
/** @test */
29+
public function it_can_change_the_default_bound_values()
30+
{
31+
$this->browse(function (Browser $browser) {
32+
$browser->visit('form/components/libraryChange')
33+
->waitForText('FormComponents')
34+
->press('Change!')
35+
->assertInputValue('biography', 'Changed!')
36+
->assertSeeIn('div[data-select-name="country"] .choices__item--selectable', 'Belgium')
37+
->assertSeeIn('div[data-select-name="countries[]"] .choices__list--multiple', 'Germany')
38+
->assertSeeIn('div[data-select-name="countries[]"] .choices__list--multiple', 'Italy')
39+
->assertInputValue('date', '2022-08-22')
40+
->assertInputValue('time', '3:14')
41+
->assertInputValue('datetime', '2022-08-22 3:14')
42+
->assertInputValue('daterange', '2022-08-22 to 2022-09-22');
43+
});
44+
}
45+
2846
/** @test */
2947
public function it_can_autosize_the_textarea()
3048
{

resources/views/form.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
:splade-id="@js($spladeId)"
66
>
77
<template #default="{!! $scope !!}">
8-
<form data-splade-id="{{ $spladeId }}" v-bind="form.$attrs" @submit.prevent="form.submit">
8+
<form data-splade-id="{{ $spladeId }}" v-bind="form.$attrs" @submit.prevent="form.submit" {!! $attributes->only('method')->merge(['method' => 'POST']) !!}>
99
<fieldset v-bind:disabled="form.processing" {!! $attributes->only('class') !!}>
1010
{{ $slot }}
1111
</fieldset>

resources/views/form/input.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
])->merge([
2525
'name' => $name,
2626
'type' => $type,
27-
'v-model' => $flatpickrOptions() ? null : $vueModel()
27+
'v-model' => $vueModel()
2828
]) }}
2929
/>
3030

resources/views/form/select.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
])->merge([
1515
'multiple' => $multiple,
1616
'name' => $name,
17-
'v-model' => $choicesOptions() ? null : $vueModel()
17+
'v-model' => $vueModel()
1818
]) }}
1919
>
2020
@if(trim($slot))

0 commit comments

Comments
 (0)