Laravel Nova: Group form fields in columns

非 Y 不嫁゛ 提交于 2021-02-19 05:30:51

问题


How can i create columns on my form fields in Laravel Nova?

For instance, i'm trying to separate the first- and lastname but don't wanna have it on two lines. I would prefere to have it next to each other, but i don't find any possibility to choose that option.

Does anyone have an idea how to solve it? Or has a package that does it? I already searched but nothing found.

Thanks


回答1:


This is currently not possible with Laravel Nova.




回答2:


This can be acheaved with this package: https://github.com/64robots/nova-fields And some custom CSS defined on certain fields. In my case it was like so:

...
->labelClasses('w-full pt-4')
->wrapperClasses('flex flex-col w-1/3 float-left flex-1 px-4 pl-8')
...

w-1/3 means 33%, and float-left is, of course, float: left. Apply float-left on 2 first fields, and the w-1/3 tree will result in 3 columns.

Example:

Whole code:

public function fields(Request $request): array
    {
        return [
            ID::make(__('ID'), 'id')->sortable(),

            \R64\NovaFields\Select::make(__('Užsakymo tipas'), 'order_type')->options([
                'equipment_rent' => __('Įrangos nuoma'),
                'entertainment_and_equipment_rent' => __('Pramogų ir įrangos nuoma'),
                'equipment_rent_inplace' => __('Įrangos nuoma iš vietos'),
            ])
                ->labelClasses('w-full pt-4')
                ->wrapperClasses('flex flex-col w-1/3 float-left flex-1 px-4 pl-8')
                ->fieldClasses('w-full py-4'),

            \R64\NovaFields\Select::make(__('Regionas'), 'region')->options([
                'vilnius' => __('Vilniaus'),
                'klaipeda' => __('Klaipėdos'),
            ])
                ->labelClasses('w-full pt-4')
                ->wrapperClasses('flex flex-col w-1/3 float-left flex-1 px-4')
                ->fieldClasses('w-full py-4'),

            \R64\NovaFields\BelongsTo::make(__('Pardavėjas'), 'seller', Seller::class)
                ->labelClasses('w-full pt-4')
                ->wrapperClasses('flex flex-col w-1/3 flex-1 px-4 pr-8')
                ->fieldClasses('w-full py-4'),

            Text::make('Test'),
            Text::make('Test another'),
        ];
    }


来源:https://stackoverflow.com/questions/53817479/laravel-nova-group-form-fields-in-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!