Crud: [question] Custom form layout

Created on 20 Oct 2016  路  9Comments  路  Source: Laravel-Backpack/CRUD

Maybe I'm not reading the docs well enough but I'm wondering how customize the form layout. For instance, how would you structure a 2-column layout? How would you tell backback that these elements go in col 1 and the others go in col 2?

Most helpful comment

Hi @gavinhewitt ,

Yes, this feature isn't that well documented, if at all. On any field you can declare "wrapperAttributes", which will place those attributes on the field's wrapper element. And if you place a class like col-md-6, you can get a two-column aspect.

For example, this would make two fields show up on the same row, in two columns:

$this->crud->addField([
   'name' => 'start_date',
   'type' => 'date',
   'label' => 'Date',
   'wrapperAttributes' => [
        'class' => 'form-group col-md-6'
   ]
]);
$this->crud->addField([
   'name' => 'end_date',
   'type' => 'date',
   'label' => 'Date',
   'wrapperAttributes' => [
        'class' => 'form-group col-md-6'
   ]
]);

All 9 comments

i think the best way to do that is to create some column divs (bootstrap's col-xx-*) by using "custom html" fields in which you add the other fields you want. The other way i can think about now would be to create a custom template that contains those two/three/etc. columns, in which you would set a section for each column and then add it to the field's parameters, though it sounds quite complicated.

Hi @gavinhewitt ,

Yes, this feature isn't that well documented, if at all. On any field you can declare "wrapperAttributes", which will place those attributes on the field's wrapper element. And if you place a class like col-md-6, you can get a two-column aspect.

For example, this would make two fields show up on the same row, in two columns:

$this->crud->addField([
   'name' => 'start_date',
   'type' => 'date',
   'label' => 'Date',
   'wrapperAttributes' => [
        'class' => 'form-group col-md-6'
   ]
]);
$this->crud->addField([
   'name' => 'end_date',
   'type' => 'date',
   'label' => 'Date',
   'wrapperAttributes' => [
        'class' => 'form-group col-md-6'
   ]
]);

Thanks for the quick replies.

@tabacitu Ok, so you can control the width of a form element by attaching an extra col-* class, but this is not what I meant. What I meant is a way to make a basic layout and 'instruct' the fields what col they should hook in to. For instance, imagine 2 columns where col-1 has the form inputs to edit a user, and next to that a preview/upload button for his userimage. Sure, I can set the wrapper classes so they are shown nicely together, but it doesn't wrap those 2 cols in a row (not tested yet), needed to start the next section. Understand what I mean?

Oh. Then I think @AurelDragut's solution would fit you better. Cheers!

Yes, I thought so :)

Hi @gavinhewitt ,

Yes, this feature isn't that well documented, if at all. On any field you can declare "wrapperAttributes", which will place those attributes on the field's wrapper element. And if you place a class like col-md-6, you can get a two-column aspect.

For example, this would make two fields show up on the same row, in two columns:

$this->crud->addField([
   'name' => 'start_date',
   'type' => 'date',
   'label' => 'Date',
   'wrapperAttributes' => [
        'class' => 'form-group col-md-6'
   ]
]);
$this->crud->addField([
   'name' => 'end_date',
   'type' => 'date',
   'label' => 'Date',
   'wrapperAttributes' => [
        'class' => 'form-group col-md-6'
   ]
]);

This definitely needs to be documented, so helpful!

It does not fit correctly
https://prnt.sc/phxp8g

   $this->crud->addField([ // select_from_array
            'name' => 'no_processo',
            'label' => "Numero do Processo",
            'type' => 'number',
            'wrapperAttributes' => [
                'class' => 'form-group col-md-6',
            ]
            // 'allows_multiple' => true, // OPTIONAL; needs you to cast this to array in your model;
        ]);
        $this->crud->addField([ // select_from_array
            'name' => 'no_processo_ant',
            'label' => "Numero do Processo Anterior",
            'type' => 'number',
            'wrapperAttributes' => [
                'class' => 'form-group col-md-6',
            ]
            // 'allows_multiple' => true, // OPTIONAL; needs you to cast this to array in your model;
        ]);

@samuk190 I've just added the col-md-6 class to two adjacent fields in the backpack demo and it looks right to me. I copied and pasted your wrapperAttributes code:

Screenshot 2019-10-11 at 15 29 21

@samuk190 I've just added the col-md-6 class to two adjacent fields in the backpack demo and it looks right to me. I copied and pasted your wrapperAttributes code:

Screenshot 2019-10-11 at 15 29 21

did you paste inside a tab? because inside a tab it works. but without a tab it doesnt work.

If that isnt the case, can you share the views (create view, field view or your project? I will compare the files)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mklahorst picture mklahorst  路  3Comments

packytagliaferro picture packytagliaferro  路  3Comments

M0H3N picture M0H3N  路  3Comments

abewartech picture abewartech  路  3Comments

bastos71 picture bastos71  路  3Comments