Laravel-Backpack / addons

A place for the Backpack community to talk about possible Backpack add-ons.
5 stars 2 forks source link

Splitting up forms over multiple cards #47

Open JoepdeJong opened 1 year ago

JoepdeJong commented 1 year ago

Hi everyone,

I have implemented blocks, which allow me to split op a crud form over multiple cards/columns using e.g. col-md-6.

Screenshot 2023-01-22 at 14 58 52

The config is similar to tabs: add 'block'=>'block_name' to a field. To customize blocks, e.g. styling and title, one can use blockOptions:

        $this->crud->setOperationSetting('blockOptions', [
            'general' => [
                'wrapper_class' => 'col-md-12 compact-form',
                'show_title' => false,
            ],
            'pickUpAddress' => [
                'wrapper_class' => 'col-md-6 compact-form',
                'title' => __('order.pick_up_address'),
                'show_title' => true,
            ],
            'deliveryAddress' => [
                'wrapper_class' => 'col-md-6 compact-form',
                'title' => __('order.delivery_address'),
                'show_title' => true,
            ],
            'goods' => [
                'wrapper_class' => 'col-md-12 compact-form',
                'title' => __('order.goods'),
                'show_title' => true,
            ],
            'goodsRetour' => [
                'wrapper_class' => 'col-md-12',
                'title' => __('order.goods_retour'),
            ]
            ]);

At the moment, I implemented this by overwriting the CrudPanel class and adding a Blocks trait. This means that it breaks when these files are updated in Backpack.

Do you know if there is any interest in this functionality? In that case, I could clean up my code, fork Backpack, and make a PR. Or are there any other possibilities to extend CrudPanel, Fields, and FieldsProtectedMethods without editing the backpack core?

pxpm commented 1 year ago

Hey @JoepdeJong thanks for providing such detail! 🙏

I always liked forms displayed like that and I think there is a simpler way for you to do that without overriding the CrudPanel class.

You can create a new create_with_blocks file, that is a copy of https://github.com/Laravel-Backpack/CRUD/blob/main/src/resources/views/crud/create.blade.php

In your CrudController CreateOperation setup, tell backpack to use this view: $this->crud->setCreateView('path.to.your.view')

You will probably need to create a custom form_content too https://github.com/Laravel-Backpack/CRUD/blob/main/src/resources/views/crud/form_content.blade.php

And I think you can achieve what you are looking for by creating those two files, without overriding nothing from the core.

Cheers

pxpm commented 1 year ago

Hey there @JoepdeJong Probably using an Operation (basically a trait that you add to crud controller)? That and the views would avoid overriding backpack crud panel class. Cheers