dactadmin 表单字段动态显示的时候无法提交

$form->select('type')
     ->options(langs('card_type'))
     ->default($page['code'])
     ->required()
     ->when(1, function (Form $form) use ($price_list) {
          $form->select('price_id', '价格策略')->options($price_list)->required();
});

当 type 不等于 1 的时候,price_id 不显示。这时候 price_id 前端是 required 状态,表单无法提交

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
最佳答案

需要用required_if

$form->select('type')
     ->options(langs('card_type'))
     ->default($page['code'])
     ->required()
     ->when(1, function (Form $form) use ($price_list) {
          $form->select('price_id', '价格策略')->options($price_list)->rules('required_if:type,1');
});
3年前 评论
wanzi 3年前
讨论数量: 1

需要用required_if

$form->select('type')
     ->options(langs('card_type'))
     ->default($page['code'])
     ->required()
     ->when(1, function (Form $form) use ($price_list) {
          $form->select('price_id', '价格策略')->options($price_list)->rules('required_if:type,1');
});
3年前 评论
wanzi 3年前

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