Laravel-Backpack / CRUD

Build custom admin panels. Fast!
https://backpackforlaravel.com
MIT License
3.08k stars 886 forks source link

Repeatable does not work in repeatable #2761

Closed maig81 closed 4 years ago

maig81 commented 4 years ago

Bug report

What I did

I have added a repeatable field in a repeatable field (nested)

$this->crud->addField([   // repeatable
            'name' => 'section',
            'label' => __('Sekcije'),
            'type' => 'repeatable',
            'tab' => __('Sekcije'),
            'fields' => [
                [
                    'name' => 'section_title',
                    'type' => 'text',
                    'label' => __('Naslov'),
                ],
                [
                    'name' => 'subsection',
                    'label' => __('Podsekcije'),
                    'type' => 'repeatable',
                    'fields' => [
                        [
                            'name' => 'subsection_subtitle',
                            'type' => 'text',
                            'label' => __('Naslov'),
                        ],

                    ],
                ]
            ]
        ]);

What I expected to happen

Expected to save nested JSON in the database similar to this

[
  {
    "section_title": "Section title",
    "subsection": "[
           {
              "subsection_subtitle":"Subsection subtitle"
           }
         ]",
  }
]

What happened

On first look, the layout looks ok, the fields are nested, but when I enter some content, it saves an extra field, so after save the data is not valid. Here is an example JSON after

[
  {
    "section_title": "test",
    "subsection": "[{\"subsection_subtitle\":\"test\"}]",
    "subsection_subtitle": "test"
  },
  {
    "subsection_subtitle": "test"
  }
]

What I've already tried to fix it

Nothing actually :(

Backpack, Laravel, PHP, DB version

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

PHP VERSION:

PHP 7.3.12 (cli) (built: Nov 19 2019 13:58:02) ( ZTS MSVC15 (Visual C++ 2017) x64 ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.12, Copyright (c) 1998-2018 Zend Technologies

LARAVEL VERSION:

v6.18.11@73bc10bb23aab7539c8ffae6d5dc3c4b277de557

BACKPACK VERSION:

4.1.x-dev@00150a6e5c7e527d2f3121730dcf8ed4dcc2b6b9

tabacitu commented 4 years ago

Right. Indeed @maig81 , you can't put a repeatable field inside another repeatable field. You get only one πŸ˜„ Sorry but we don't intend to add this feature in the near future. It would be a MONSTROUS challenge, for very little benefit - I expect very very few people need this. And the effort to create, and maintain such a field and such a JSON will make it a pain, for both Backpack maintainers and the developers that use it. If you end up needing something this complicated, that may be a sign that you need to rethink your DB design.

However, you can use the table field - which works well inside repeatable. Also, you can use the InlineCreate operation inside the relationship field.

Cheers!

PS. If anybody else stumbles upon this, and really really need it, please reply.

kamilkozak commented 4 years ago

@tabacitu I think this is very necessary. The repeatable field is very well suited for editing embedded documents in mongodb. Sometimes documents are nested deeper. In fact, mongodb allows 100 nesting levels. This is normal in the world of nonrelational databases. I will be forever grateful if you can do it.

By the way, please fix the fake field because it doesn't work with mongodb. Problem causing linevendor/backpack/crud/src/app/Library/ CrudPanel/Traits/AutoSet.php: 82

dividy commented 4 years ago

I can relate.

I used a repeatable for adding a "products" field. The customer wants to be able to add photos to the products. I was going for nested repeatable fields but I wanted to check here first ;)

@tabacitu you're right about the JSON becoming a pain to maintain, unless you intercept it and transform it into real fields (just a thought)

tabacitu commented 4 years ago

Thanks for the feedback guys!

chivomd commented 4 years ago

I don't know if is a bug or not. But when adding a table field into a repeatable one. When you add a repeatable group and after that you add a row in the table field, rows are duplicated, triplicated, etc... Only the last repeatable element is working normally. The other ones are adding unnecessary rows like they were accumulating the number of rows to add when button is clicked depending on the repeatable position.

Captura de pantalla 2020-06-23 a las 18 12 09

dividy commented 4 years ago

@chivomd seems like a nasty event bug

tabacitu commented 4 years ago

Ouch @chivomd - sounds like a bug indeed. I've moved your text here https://github.com/Laravel-Backpack/CRUD/issues/3012 to talk individually about that problem. Thanks!

matthbon commented 3 years ago

Would be really nice if this would work. I am trying to make a dynamic page builder where you can make content blocks with text or like a carousel module where you can select multiple images.

So a repeatable in repeatable would be necessary for this. Or maybe someone has another idea how to fix this.

kee0624 commented 3 years ago

Agree. When integrated with the carousel, I think a nested repeatable field is very necessary.

For example below situation

  [hero_item] - repeatable field
    [hero_item_img]
    [hero_item_title]
    [hero_item_buttons]
      [button] - repeatable field
        [label]
        [url]
        [type]

but since there is no solution for now. What I did is fixed the button length using the general field.

enefeka commented 2 years ago

Any news on this? I also stumbled upon this and would really love repeatable inside repeatable feature. Thanks.

pxpm commented 2 years ago

Hello @enefeka this migth be possible after we refactor repeatable in 4.2 it's already on the roadmap. Currently how we implement it, is not possible or easily feasible at all.

enefeka commented 2 years ago

Thanks @pxpm, I guess you don't have an approximate release date yet.

tabacitu commented 2 years ago

@enefeka we'll probably release Backpack 4.2 by the end of Nov 2021. But we can't promise it'll allow repeatable inside repeatable. We won't know until we rewrite the field entirely... Sorry to bring no actual news πŸ˜…

ampedweb commented 2 years ago

I'm looking for something exactly like this. So hopefully you guys will do it! =) fingers crossed. I'm currently writing a "Food menu" system, and the menu has sections to it. So top level entity is "Main menu" then you have sections inside it like "Speciality Burgers", "Light Bites" and then nested inside those you have the actual dishes. So a nested repeatable would be great right now! =)

I think I can make it work with a table though...