From b9ae0348b96e8b31dfd899d9b42360c94d4d7216 Mon Sep 17 00:00:00 2001 From: xiamiao Date: Wed, 10 Jul 2024 19:50:32 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix(form):=20=E4=BF=AE=E5=A4=8Dvalidator?= =?UTF-8?q?=E5=9B=9E=E8=B0=83=E4=B8=AD=E7=AC=AC=E4=B8=80=E4=B8=AA=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=B8=A6=E6=9C=89=E5=A4=9A=E4=BD=99=E7=9A=84=E5=BC=95?= =?UTF-8?q?=E5=8F=B7(#2931)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/ui/form/src/use-form-field.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/ui/form/src/use-form-field.ts b/packages/ui/form/src/use-form-field.ts index d5a64da5a..8b9af39d6 100644 --- a/packages/ui/form/src/use-form-field.ts +++ b/packages/ui/form/src/use-form-field.ts @@ -38,8 +38,22 @@ export const useFormField = (props: UseFormFieldProps) => // TODO: rules 处理成 Async Validate 的指定结构 const fieldMD5 = stringify(field as FormFieldPath) - - const validater = new Validater({ [fieldMD5]: fieldRules }) + const modifiedFieldRules = fieldRules.map((rule) => { + if (rule.validator) { + return { + ...rule, + validator: (validatorRule: any, value: any, cb: any) => { + const field = validatorRule.field.replace(/"/g, '') + const fullField = validatorRule.fullField.replace(/"/g, '') + rule.validator({ ...validatorRule, field, fullField }, value, cb) + }, + } + } else + return { + ...rule, + } + }) + const validater = new Validater({ [fieldMD5]: modifiedFieldRules }) return validater.validate( { [fieldMD5]: From 9086f4c13c65b4e88ce8ae0e4d986c7225cb7c83 Mon Sep 17 00:00:00 2001 From: xiamiao Date: Wed, 10 Jul 2024 19:54:57 +0800 Subject: [PATCH 2/3] =?UTF-8?q?chore(form):=20=E7=94=9F=E6=88=90=E5=8F=98?= =?UTF-8?q?=E6=9B=B4=E8=AE=B0=E5=BD=95=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/curvy-falcons-confess.md | 5 +++++ .changeset/old-penguins-grin.md | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 .changeset/curvy-falcons-confess.md create mode 100644 .changeset/old-penguins-grin.md diff --git a/.changeset/curvy-falcons-confess.md b/.changeset/curvy-falcons-confess.md new file mode 100644 index 000000000..cb78995bc --- /dev/null +++ b/.changeset/curvy-falcons-confess.md @@ -0,0 +1,5 @@ +--- +"@hi-ui/form": patch +--- + +fix: 修复 validator 回调中第一个参数带有多余的引号 diff --git a/.changeset/old-penguins-grin.md b/.changeset/old-penguins-grin.md new file mode 100644 index 000000000..68ea9ddde --- /dev/null +++ b/.changeset/old-penguins-grin.md @@ -0,0 +1,5 @@ +--- +"@hi-ui/hiui": patch +--- + +feat(form): 修复 validator 回调中第一个参数带有多余的引号 From c11487986c8152453b81f141352621a33a408adb Mon Sep 17 00:00:00 2001 From: xiamiao Date: Wed, 24 Jul 2024 10:29:26 +0800 Subject: [PATCH 3/3] =?UTF-8?q?chore(form):=20=E6=B7=BB=E5=8A=A0=E6=B3=A8?= =?UTF-8?q?=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/old-penguins-grin.md | 2 +- packages/ui/form/src/use-form-field.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.changeset/old-penguins-grin.md b/.changeset/old-penguins-grin.md index 68ea9ddde..f423155fa 100644 --- a/.changeset/old-penguins-grin.md +++ b/.changeset/old-penguins-grin.md @@ -2,4 +2,4 @@ "@hi-ui/hiui": patch --- -feat(form): 修复 validator 回调中第一个参数带有多余的引号 +fix(form): 修复 validator 回调中第一个参数带有多余的引号 diff --git a/packages/ui/form/src/use-form-field.ts b/packages/ui/form/src/use-form-field.ts index 8b9af39d6..d07e3194d 100644 --- a/packages/ui/form/src/use-form-field.ts +++ b/packages/ui/form/src/use-form-field.ts @@ -39,6 +39,8 @@ export const useFormField = (props: UseFormFieldProps) => // TODO: rules 处理成 Async Validate 的指定结构 const fieldMD5 = stringify(field as FormFieldPath) const modifiedFieldRules = fieldRules.map((rule) => { + // 重写 rule 的 validator 函数,正则匹配 validatorRule 中的 field 和 fullField,消除 field 和 fullField 中的双引号 + // issue:https://github.com/XiaoMi/hiui/issues/2931 if (rule.validator) { return { ...rule,