From acceeee59ca18fc59dc94508e934bde09a43e303 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Thu, 4 May 2023 15:58:39 +0800 Subject: [PATCH] fix: the label of some radio is displayed incorrectly (#3878) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind bug /area console /milestone 2.6.x #### What this PR does / why we need it: 修复部分 FormKit 的 radio 表单项的 label 设置不正确的问题。目前影响范围: 1. 使用了 type 为 `menuCheckbox` `menuRadio` 并将 validation 设置为了 `required`。 ![image](https://user-images.githubusercontent.com/21301288/235104292-5324be1d-af48-4c7f-8f31-30a9b3dc9c02.png) #### Which issue(s) this PR fixes: Fixes #3876 #### Does this PR introduce a user-facing change? ```release-note 修复部分 FormKit 的 radio 表单项的 label 设置不正确的问题。 ``` --- console/src/formkit/plugins/required-asterisk.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/console/src/formkit/plugins/required-asterisk.ts b/console/src/formkit/plugins/required-asterisk.ts index 8e7740090..63b7e65d8 100644 --- a/console/src/formkit/plugins/required-asterisk.ts +++ b/console/src/formkit/plugins/required-asterisk.ts @@ -1,8 +1,7 @@ import type { FormKitNode } from "@formkit/core"; -const isCheckboxAndRadioMultiple = (node) => - (node.props.type === "checkbox" || node.props.type === "radio") && - node.props.options; +const hasLegendNode = (node) => + ["checkbox", "radio", "repeater", "group"].includes(node.props.type); export default function requiredAsterisk(node: FormKitNode) { node.on("created", () => { @@ -18,7 +17,7 @@ export default function requiredAsterisk(node: FormKitNode) { ); if (isRequired) { - if (isCheckboxAndRadioMultiple(node)) { + if (hasLegendNode(node)) { sectionsSchema.legend = { children: ["$label", " *"], };