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

7kjnsjlb  于 2024-01-05  发布在  PHP
关注(0)|答案(2)|浏览(192)

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

  1. public static function form(Form $form): Form
  2. {
  3. return $form
  4. ->schema([
  5. Wizard::make([
  6. Wizard\Step::make('First Step')
  7. ->schema([
  8. TextInput::make('title')->required(),
  9. Forms\Components\Actions::make([
  10. Action::make('Custom Modal')
  11. ->button()
  12. ->form([
  13. TextInput::make('price')->prefix('$')->required(),
  14. ])
  15. ]),
  16. Wizard\Step::make('Second Step')
  17. ->schema([
  18. //...
  19. ]),
  20. ]),
  21. ]);
  22. }

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

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

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

bzzcjhmw

bzzcjhmw1#

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

  1. //....
  2. Wizard\Step::make('First Step')
  3. ->schema([
  4. TextInput::make('title')->required(),
  5. Hidden::make('price'),
  6. Forms\Components\Actions::make([
  7. Action::make('Custom Modal')
  8. ->button()
  9. ->form([
  10. TextInput::make('price')->prefix('$')->required()
  11. ->default(
  12. function (MyModel $record = null) {
  13. return $record?->price;
  14. }
  15. ),
  16. ])
  17. ->action(function (Set $set, array $data) {
  18. $set('price', $data['price']);
  19. }),
  20. ]),
  21. ]),
  22. //....

字符串

展开查看全部
ibrsph3r

ibrsph3r2#

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

  1. //....
  2. Wizard\Step::make('First Step')
  3. ->schema([
  4. TextInput::make('title')->required(),
  5. Hidden::make('price'),
  6. Forms\Components\Actions::make([
  7. Action::make('Custom Modal')
  8. ->button()
  9. ->form([
  10. TextInput::make('price')->prefix('$')->required()
  11. ->default(
  12. function (MyModel $record = null) {
  13. return $record?->price;
  14. }
  15. ),
  16. ])
  17. ->action(function (Set $set, array $data) {
  18. $set('price', $data['price']);
  19. }),
  20. ]),
  21. ]),
  22. //....

字符串

展开查看全部

相关问题