Laravel Nova:将列中的表单字段分组 [英] Laravel Nova: Group form fields in columns

查看:93
本文介绍了Laravel Nova:将列中的表单字段分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Laravel Nova中的表单字段上创建列?

例如,我正在尝试将姓氏和姓氏分开,但不想在两行中都使用它.我希望将其并排放置,但是我找不到选择该选项的任何可能性.

有人知道如何解决吗?或是否有提供此服务的包装?我已经搜索过,但没有找到.

谢谢

解决方案

可以通过以下软件包来实现:

整个代码:

 公共功能字段(请求$ request):数组{返回 [ID :: make(__('ID'),'id')-> sortable(),\ R64 \ NovaFields \ Select :: make(__('Užsakymotipas'),'order_type')-> options(['equipment_rent'=>__('Įrangosnuoma'),'entertainment_and_equipment_rent'=>__('Pramogųirįrangosnuoma'),'equipment_rent_inplace'=>__('Įrangosnuomaiš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'),文字:: make('Test'),Text :: make('Test another'),];} 

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

解决方案

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'),
        ];
    }

这篇关于Laravel Nova:将列中的表单字段分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆