dcat-admin icon indicating copy to clipboard operation
dcat-admin copied to clipboard

Form字段动态显示时提交的数据有点问题

Open krissss opened this issue 3 years ago • 3 comments

  • Laravel Version: 8.80.0
  • PHP Version: 7.4.27
  • Dcat Admin Version: 2.1.7-beta

Description:

当 when 中的 form 使用同名 column 时,表单提交会提交所有参数,导致数据获取有问题

Steps To Reproduce:

return Form::make(new Test(), function (Form $form) {
    $form->radio('radio')
        ->when(1, function (Form $form) {
            $form->text('text1');
        })
        ->when(2, function (Form $form) {
            $form->text('text1');
        })
        ->options([
            1 => 'A',
            2 => 'B',
        ])
        ->default(1);
})->saving(function (Form $form) {
    dd($form->input());
});
  1. 显示没有问题
  2. 提交时,提交了所有input值:radio=&radio=1&text1=111&text1=&_token=xxxxx
  3. dd 结果:array:3 [ "radio" => "1" "text1" => null "_token" => "xxxxx" ]

krissss avatar Jan 25 '22 06:01 krissss

text1 别一样

heartshuai avatar Feb 21 '22 07:02 heartshuai

报的就是这个问题,知道不能用同 name 的,但是不能 name 的话后端要处理数据还是很麻烦的,所以在想有没有办法能够支持同 name

krissss avatar Feb 21 '22 07:02 krissss

使用数据做条件判断,可以避免这个问题:

$form->radio('radio')
        ->when([1,2], function (Form $form) {
            $form->text('text1');
        })
        ->when(3, function (Form $form) {
            $form->text('text2');
        })
        ->options([
            1 => 'A',
            2 => 'B',
           3 =>'C',
        ])
        ->default(1);

Sparkinzy avatar Mar 04 '22 03:03 Sparkinzy

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 31 '22 06:08 stale[bot]