protonemedia / laravel-splade

💫 The magic of Inertia.js with the simplicity of Blade 💫 - Splade provides a super easy way to build Single Page Applications (SPA) using standard Laravel Blade templates, and sparkle it to make it interactive. All without ever leaving Blade.
https://splade.dev
MIT License
1.47k stars 112 forks source link

Set specific date range in x-splade-input with flatpickr #551

Closed p4rad0xus closed 8 months ago

p4rad0xus commented 8 months ago

Description:

In a Blade file I use a x-splade-form to edit a Model. The Model contains an attribute named "start_date" and "end_date". This attributes contains a string with a date in the format "Y-m-d". The information for this attributes comes from a x-splade-input date range field and will be separated.

To edit the date in the form I want also to use x-splade-input date range. But I don't know how to fill the input field with the informations of "start_date" and "end_date. With the config option defaultDate on the date attribute I can set a date which would be shown, but the submitted form does contains instead a empty string.

Form to edit

<x-splade-form :default="$myModel">
    <x-splade-input name="name" />
    <x-splade-input name="date_range" date="{defaultDate: '{{ $myModel->start_date }} to {{ $myModel->end_date }}'}" range />
</x-splade-form>
dusp2k commented 8 months ago

I think you can access the data by using form.start_date and form.end_date. Just like you would use data.some_variabele in a <x-splade-data> tag

p4rad0xus commented 8 months ago

Thank you for your answer but I don't want to use the value from the input field in the form. The field display the passing data on the website. If I submit the form and want to get the value of the field in the FormRequest class with $this->date_range its returns null.

Example The Model $myModel contains the following values:

In the Blade file I use this form:

<x-splade-form :default="$myModel">
    <x-splade-input name="name" />
    <x-splade-input name="date_range" date="{defaultDate: '{{ $myModel->start_date }} to {{ $myModel->end_date }}'}" range />
</x-splade-form>

On the website I see the expected values also the DOM for the input field with the name attribute "date_range".

Bildschirmfoto 2024-03-06 um 13 50 20 Bildschirmfoto 2024-03-06 um 13 54 14

If the unchanged form is submitted the intended FormRequest class receive on $this->name the value "Model 1" and under $this->date_range the value null.

Bildschirmfoto 2024-03-06 um 14 06 37

Only if the period is selected again do I receive a string in the FormRequest.