dcat-admin
dcat-admin copied to clipboard
Form字段动态显示时提交的数据有点问题
- 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());
});
- 显示没有问题
- 提交时,提交了所有input值:radio=&radio=1&text1=111&text1=&_token=xxxxx
- dd 结果:array:3 [ "radio" => "1" "text1" => null "_token" => "xxxxx" ]
text1 别一样
报的就是这个问题,知道不能用同 name 的,但是不能 name 的话后端要处理数据还是很麻烦的,所以在想有没有办法能够支持同 name
使用数据做条件判断,可以避免这个问题:
$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);
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.