Dcat Admin 数据表单中multipleSelectTable()选中后提交不更新表单的问题

如上图所示,想要实现的效果:

1、视窗①是一个数据表单,最后一个字段”机构管理员”是一个multipleSelectTable()类型字段;
2、点击该字段弹出视窗②选择管理员(User)的表单弹窗;
3、在视窗②中点击“新增”按钮,弹出添加用户的视窗③;
4、视窗③中填写用户信息,提交后需要刷新视窗②列表数据;
5、视窗②中勾选用户后,提交,则视窗①的“机构管理员”中插入选中的值;

目前存在的问题:

1、上述步骤4中,新增用户提交后,刷新的不是视窗②,而刷新的是视窗①;
2、上述步骤5中,勾选后提交,选定的数据不会插入到视窗①的“机构管理员”中;

注:以上两个问题,只有在新增用户时存在,如果不新增直接从列表选定用户提交,是正常插入的。

代码片段

数据表单代码如下:

protected function form()
    {
        return Form::make(new Organization(), function (Form $form) {
            $form->text('name')->required();
            $form->text('short_name');
            $form->text('domain')->required();
            $form->dateRange('contract_at', 'expires_at', '服务周期')->help('留空表示不舍期限');
            $form->switch('status')->default(true);
            $form->multipleSelectTable('administrators', '机构管理员')
                ->title('机构管理员')
                ->dialogWidth('50%') // 弹窗宽度,默认 800px
                ->from(UserTable::make(['id' => $form->getKey()])) // 设置渲染类实例,并传递自定义参数
                ->model(User::class, 'id', 'name'); // 设置编辑数据显示
        });
    }

弹窗表格UserTable代码如下:

<?php

namespace App\Admin\Renderable;

use App\Models\User;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class UserTable extends LazyRenderable
{
    public function grid(): Grid
    {
        // 获取外部传递的参数
        $id = $this->id;

        return Grid::make(new User(), function (Grid $grid) {
            $grid->column('id');
            $grid->column('name');
            $grid->column('mobile');
            $grid->column('email');
            $grid->column('created_at');
            $grid->column('updated_at');
            $grid->quickSearch(['id', 'name', 'mobile', 'email']);
            $grid->paginate(10);
            // $grid->disableActions();
            $grid->showCreateButton();
            $grid->showRefreshButton();
            $grid->setResource('users');
            $grid->enableDialogCreate();
            $grid->setDialogFormDimensions('600px', 'auto');
            $grid->filter(function (Grid\Filter $filter) {
                $filter->like('name')->width(4);
            });
        });
    }
}
正在努力学习的小逗比 [ dobeen.net ]
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 6
DogLoML

要加一段js,把新建的用户追加到select2的选项中去触发它选中。

9个月前 评论
Mutoulee (楼主) 9个月前
DogLoML (作者) 9个月前
DogLoML (作者) 9个月前
Mutoulee (楼主) 9个月前
Mutoulee

继续求问

9个月前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!