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 状态,表单无法提交

《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
最佳答案

需要用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年前

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