Laravel-Backpack / community-forum

A workspace to discuss improvement and feature ideas, before they're actually implemented.
28 stars 0 forks source link

[Bug] date_range field inside repeatable field doesn't work #822

Closed april-zeus closed 8 months ago

april-zeus commented 8 months ago

Bug report

What I did

I updated from backpack 5 to 6.

In my CrudController with repeatable field, I have those fields

        CRUD::addField( [
                    'name' => 'start_date,end_date',
                    'type' => 'date_range',
                    'label' => 'Date',
                    'wrapper' => ['class' => 'form-group col-md-4'],
                ],
        );

        CRUD::addField([
            'name' => 'slides',
            'label' => 'Slides',
            'type' => 'repeatable',
            'subfields' => [
                [
                    'name' => 'primary_button_text',
                    'label' => 'Primary button text',
                    'type' => 'text',
                ],
                [
                    'name' => 'start_date,end_date',
                    'type' => 'date_range',
                    'label' => 'Date',
                    'wrapper' => ['class' => 'form-group col-md-4'],
                ],
            ],
            'new_item_label' => 'New slide',
            'reorder' => true,
        ]);

What I expected to happen

I expected to have a date range field in CRUD and data passed from frontend to backend this way:

start_date: 2024-01-29 00:00:00
end_date: 2024-01-29 23:59:59
slides: 
slides[0][primary_button_text]: test
slides[0][start_date]: 2024-01-13 00:00:00
slides[0][end_date]: 2024-02-11 23:59:59

What happened

Data got passed this way

start_date: 2024-01-29 00:00:00
end_date: 2024-01-29 23:59:59
slides: 
slides[0][primary_button_text]: test
slides[0][start_date: 2024-01-13 00:00:00
end_date]: 2024-02-11 23:59:59

image

What I've already tried to fix it

Bug occurs only with date_range in repeatable.subfields. It works fine as a separate field. I've tried updating packages

Is it a bug in the latest version of Backpack?

After I run composer update backpack/crud the bug... is it still there? Yes

Backpack, Laravel, PHP, DB version

When I run php artisan backpack:version the output is:

### PHP VERSION:
PHP 8.2.15 (cli) (built: Jan 20 2024 14:17:05) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.15, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.15, Copyright (c), by Zend Technologies
    with Xdebug v3.3.1, Copyright (c) 2002-2023, by Derick Rethans

### LARAVEL VERSION:
10.42.0.0

### BACKPACK PACKAGE VERSIONS:
backpack/basset: 1.2.2
backpack/crud: 6.6.0
backpack/filemanager: 3.0.7
backpack/generators: v4.0.2
backpack/pro: 2.1.0
backpack/theme-coreuiv2: 1.2.2
kamil3658 commented 8 months ago

I had same issue. It crashes in repeatable field.

pxpm commented 8 months ago

Hey @april-zeus and @kamil3658

I tried to reproduce the issues you mentioned and I wasn't able to.

I receive the expected input in the request:

[ // Date_range
    'name'       => 'start_date,end_date', // a unique name for this field
    'label'      => 'Date Range',
    'type'       => 'date_range',
    'tab' => 'Time and space',
],

image

Can you check if you have that field overwritten in your resources/views/vendor/backpack/pro/fields/date_range.blade.php ?

If you do it's possible that you didn't get the updated files (even if you updated backpack/pro), because if there is a developer field in app resources, we will always use that instead of the package file.

If I recall correctly this was a previous issue that we fixed.

Also note that if you changed your date/locale preferences in config, you may need to update the field to display accordingly, have a look at field extra options if any are needed in your cases: https://backpackforlaravel.com/docs/6.x/crud-fields#date_range-pro

Cheers

april-zeus commented 8 months ago

@pxpm thank you for responding. I did some more digging. I created a new project just to be sure my old project doesn't influence this behavior in any way, and I was able to recreate this issue. It appears only update action has this problem, create operation works just fine.

Image

In previous version of backpack we had repeatable field saved in database as json. I think data type may be a problem.

To make it easier, I created a repo with an example project https://github.com/april-zeus/example-backpack Please note those files:

pxpm commented 8 months ago

Thanks @april-zeus really appreciate. A reproduction repo and all clap clap, you will spoil me 🙏

I will pull the repo in tomorrow and give it a try and come back to you with my findings 👍

Thanks again 🙏

pxpm commented 8 months ago

Hey @april-zeus thank you very much for the reproduction repo, I was testing the field in the wrong place in my first attempt to reproduce it. I was able to easily reproduce the issue in your repo and I've already released backpack/pro v2.1.2 with the fix.

It should take a little bit of time for our private repository to pick the new released version, and then you should be able to get the fix with a composer update backpack/pro.

Thanks again for raising the issue and helping in the debug 🙏

Cheers