laravel-splade icon indicating copy to clipboard operation
laravel-splade copied to clipboard

x-splade-rehydrate doesn't reload content if SpladeForm submit

Open p4rad0xus opened this issue 9 months ago • 1 comments

  • Laravel Version: 10.17.1
  • PHP Version: 8.2.10
  • Splade JS Version (npm): 1.4.16
  • Splade PHP Version (composer):1.4.16
  • Dev environment (OS, Sail/Valet/etc): macOS Ventura, Sail

Description:

On a Blade page I use a table and a form. To create the table I use SpladeForm in the controller.

When the form is sent, the contents of the table should be reloaded using x-splade-rehydrate. Instead the page is reloaded and the new entry is displayed. If I remove the stay attribute on the x-splade-form tag and add ->stay() to the SpladeForm instead, you stay on the page but the table is not reloaded.

I have the same behavior when I use the SpladeForm class.

Steps To Reproduce Issue:

In the frontend my site looks like this:

<div>
    <div>
        <x-splade-form :for="$form" stay @success="$splade.emit('entry-added')" />
    </div>
    <div>
        <x-splade-rehydrate on="entry-added">
            <x-splade-table :for="$table" :reset-button="false">
                <x-slot:empty-state>
                    <p>
                        No entries.
                    </p>
                </x-slot:empty-state>
            </x-splade-table>
        </x-splade-rehydrate>
    </div>
</div>

My index function in the controller:

TableEntrys is a SpladeTable.

public function index()
{
    return view('/tabel_entries.index', [
        'table' => TableEntrys::class,
        'form' => SpladeForm::make()
            ->action(route('table_entry.store'))
            ->fields([
                Input::make('title'),
                Submit::make()
                    ->label('Add')
            ])
    ]);
}

My store function in the controller:

public function store(TableEntryFormRequest $request)
{
    TableEntry::create($request->validated());
     return redirect($request->getRequestUri());
}

p4rad0xus avatar Sep 28 '23 16:09 p4rad0xus

If I just use the x-splade-form component in the Blade file, the rehydration works as expected.

<x-splade-form action="{{ route('table_entry.store') }}"
                            @success="$splade.emit('entry-added')"
                            class="flex flex-row items-end space-x-4"
                            stay>
</x-splade-form>

Is it in this solution possible to reset the formula if the submit was a success?

Do anyone know a solution for the rehydration by using the SpladeForm?

p4rad0xus avatar Feb 19 '24 21:02 p4rad0xus