php 在filamentv3中的表单中间放置一个模态表单

7kjnsjlb  于 11个月前  发布在  PHP
关注(0)|答案(2)|浏览(135)

如何使“价格”被识别为表单的成员?

public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Wizard::make([
                    Wizard\Step::make('First Step')
                        ->schema([
                            TextInput::make('title')->required(),
                             Forms\Components\Actions::make([
                                Action::make('Custom Modal')
                                    ->button()
                                    ->form([
                                        TextInput::make('price')->prefix('$')->required(),
                                    ])
                        ]),
                    Wizard\Step::make('Second Step')
                        ->schema([
                                //...
                        ]),
                ]),
            ]);
    }

字符串
当我提交表单时,它传递了这个错误:

SQLSTATE[23000]:违反完整性约束:1048列'price'不能为null。

一般来说,它并不适用于我放在模态中的每个列。

bzzcjhmw

bzzcjhmw1#

我已经试着找出问题所在。你可以试试我的代码,我百分之百确定。

//....
Wizard\Step::make('First Step')
    ->schema([
        TextInput::make('title')->required(),
        Hidden::make('price'),
        Forms\Components\Actions::make([
            Action::make('Custom Modal')
                ->button()
                ->form([
                    TextInput::make('price')->prefix('$')->required()
                    ->default(
                        function (MyModel $record = null) {
                            return  $record?->price;
                        }
                    ),
                ])
                ->action(function (Set $set, array $data) {
                    $set('price', $data['price']);
                }),
        ]),

    ]),
//....

字符串

ibrsph3r

ibrsph3r2#

经过测试了很多方法,现在这是答案:

//....
Wizard\Step::make('First Step')
    ->schema([
        TextInput::make('title')->required(),
        Hidden::make('price'),
        Forms\Components\Actions::make([
            Action::make('Custom Modal')
                ->button()
                ->form([
                    TextInput::make('price')->prefix('$')->required()
                    ->default(
                        function (MyModel $record = null) {
                            return  $record?->price;
                        }
                    ),
                ])
                ->action(function (Set $set, array $data) {
                    $set('price', $data['price']);
                }),
        ]),

    ]),
//....

字符串

相关问题