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'),
],
],
]
]
]);
Expected to save nested JSON in the database similar to this
[
{
"section_title": "Section title",
"subsection": "[
{
"subsection_subtitle":"Subsection subtitle"
}
]",
}
]
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"
}
]
Nothing actually :(
When I run php artisan backpack:version the output is:
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
v6.18.11@73bc10bb23aab7539c8ffae6d5dc3c4b277de557
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.
@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
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)
Thanks for the feedback guys!
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.

@chivomd seems like a nasty event bug
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!
Most helpful comment
Right. Indeed @maig81 , you can't put a
repeatablefield inside anotherrepeatablefield. 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
tablefield - which works well insiderepeatable.Also, you can use the InlineCreate operation inside the
relationshipfield.Cheers!
PS. If anybody else stumbles upon this, and really _really_ need it, please reply.