Skip to content

Commit

Permalink
fix(form): validator 中的 value 类型更新为 any (#2406)
Browse files Browse the repository at this point in the history
* fix(form): validator 中的 value 类型更新为 any

* fix(form): validator 中的 value 类型更新为 any
  • Loading branch information
oasis-cloud authored Jul 3, 2024
1 parent 5c92953 commit f980240
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/packages/form/demos/h5/demo1.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import { Form, Button, InputNumber, Input, TextArea } from '@nutui/nutui-react'
import { FormItemRuleWithoutValidator } from '@/packages/formitem/types'

const Demo1 = () => {
return (
Expand All @@ -21,6 +22,14 @@ const Demo1 = () => {
rules={[
{ max: 5, message: '字段A不能超过5个字' },
{ required: true, message: '请输入字段A' },
{
validator: (
ruleCfg: FormItemRuleWithoutValidator,
value: string
) => {
return value.length > 5
},
},
]}
>
<Input
Expand Down
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
},
},
]}
>
<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

0 comments on commit f980240

Please sign in to comment.