Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(form): validator 中的 value 类型更新为 any #2406

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/packages/form/demos/taro/demo1.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react'
import {
Form,
Button,
InputNumber,
Form,
Input,
InputNumber,
TextArea,
} from '@nutui/nutui-react-taro'
import { FormItemRuleWithoutValidator } from '@/packages/formitem/types'

const Demo1 = () => {
return (
Expand All @@ -27,6 +28,14 @@ const Demo1 = () => {
rules={[
{ max: 5, message: '字段A不能超过5个字' },
{ required: true, message: '请输入字段A' },
{
validator: (
ruleCfg: FormItemRuleWithoutValidator,
value: string
) => {
return value.length > 5
},
},
Comment on lines +31 to +38
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请更新验证器函数中的 value 类型。

验证器函数中的 value 类型应与 FormItemRule 接口中的更新保持一致。

-                value: string
+                value: any
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{
validator: (
ruleCfg: FormItemRuleWithoutValidator,
value: string
) => {
return value.length > 5
},
},
{
validator: (
ruleCfg: FormItemRuleWithoutValidator,
value: any
) => {
return value.length > 5
},
},

]}
>
<Input
Expand Down
2 changes: 1 addition & 1 deletion src/packages/formitem/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface FormItemRuleWithoutValidator {
export interface FormItemRule extends FormItemRuleWithoutValidator {
validator?: (
ruleCfg: FormItemRuleWithoutValidator,
value: string
value: any
) => boolean | string | Promise<boolean | string>
}

Expand Down
Loading