z-song / laravel-admin

Build a full-featured administrative interface in ten minutes
https://laravel-admin.org
MIT License
11.15k stars 2.82k forks source link

关于不同select条件下radio的默认选中和保存问题 #5751

Open Benjun-Lv opened 1 year ago

Benjun-Lv commented 1 year ago

Description:

我的问题是,我有select选项,比如叫type,里面有两个值,0,1;然后在不同的值下面,有个radio框的status字段,都给了默认值为0,但是页面上却无法选中,原因是在select0,1的情况下,radio里面的name都叫status,如果此时我把他改为status_1,status_2,页面是可以选中了,但是无法保存,因为我数据库字段叫status

代码如下

      $form->select('type', __('流程类型'))->options(
           [
              0 => '类型1',
              1 => '类型1'
          ])->when(0,function(Form $form) {
              $form->radio('status',__('状态'))->options([
                   0 => '是',
                   1  => '否'
               ])->default(0)
        })->when(1,function(Form $form) {
              $form->radio('status',__('状态'))->options([
                   0 => '是',
                   1  => '否'
               ])->default(0)

        }) ->default(0)

Steps To Reproduce:

rommelbin commented 1 year ago

Hello! I have the same problem. Does someone find the solution?

explore-pu commented 1 year ago

你这不是脱了裤子放屁吗?