Skip to content

Commit

Permalink
feat: 补充 FormItem 文档 getValueProps 接口额外说明
Browse files Browse the repository at this point in the history
  • Loading branch information
LongHaoo committed Dec 16, 2023
1 parent 3a2cf49 commit a9beed5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/form/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Form field component for data bidirectional binding, validation, layout, and so
| dependencies | Set the dependency field. See [below](#dependencies) | [NamePath](#namepath)\[] | - | |
| extra | The extra prompt message. It is similar to help. Usage example: to display error message and prompt message at the same time | ReactNode | - | |
| getValueFromEvent | Specify how to get value from event or other onChange arguments | (..args: any\[]) => any | - | |
| getValueProps | Additional props with sub component | (value: any) => any | - | 4.2.0 |
| getValueProps | Additional props with sub component (the component will traverse the return value for update, and attribute values of type 'function' will be ignored, resulting in abnormal updates) | (value: any) => Record<string, any> | - | 4.2.0 |
| hasFeedback | Used with `validateStatus`, this option specifies the validation status icon. Recommended to be used only with `Input`. Also, It can get feedback icons via icons prop. | boolean \| { icons: [FeedbackIcons](#feedbackicons) } | false | icons: 5.9.0 |
| help | The prompt message. If not provided, the prompt message will be generated by the validation rule. | ReactNode | - | |
| hidden | Whether to hide Form.Item (still collect and validate value) | boolean | false | 4.4.0 |
Expand Down
22 changes: 21 additions & 1 deletion components/form/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const validateMessages = {
| dependencies | 设置依赖字段,说明[见下](#dependencies) | [NamePath](#namepath)\[] | - | |
| extra | 额外的提示信息,和 `help` 类似,当需要错误信息和提示文案同时出现时,可以使用这个。 | ReactNode | - | |
| getValueFromEvent | 设置如何将 event 的值转换成字段值 | (..args: any\[]) => any | - | |
| getValueProps | 为子元素添加额外的属性 | (value: any) => any | - | 4.2.0 |
| getValueProps | 为子元素添加额外的属性 (组件会依赖返回值对比更新,类型为 'function' 的属性值会被忽略,导致异常更新) | (value: any) => Record<string, any> | - | 4.2.0 |
| hasFeedback | 配合 `validateStatus` 属性使用,展示校验状态图标,建议只配合 Input 组件使用 此外,它还可以通过 Icons 属性获取反馈图标。 | boolean \| { icons: [FeedbackIcons](#feedbackicons) } | false | icons: 5.9.0 |
| help | 提示信息,如不设置,则会根据校验规则自动生成 | ReactNode | - | |
| hidden | 是否隐藏字段(依然会收集和校验字段) | boolean | false | 4.4.0 |
Expand Down Expand Up @@ -566,6 +566,26 @@ Form.Item 默认绑定值属性到 `value` 上,而 Switch、Checkbox 等组件
</Form.Item>
```

### 自定义 validator 没有效果

这是由于你的 `validator` 有错误导致 `callback` 没有执行到。你可以选择通过 `async` 返回一个 promise 或者使用 `try...catch` 进行错误捕获:

```jsx
validator: async (rule, value) => {
throw new Error('Something wrong!');
}

// or

validator(rule, value, callback) => {
try {
throw new Error('Something wrong!');
} catch (err) {
callback(err);
}
}
```

### name 为数组时的转换规则?

`name` 为数组时,会按照顺序填充路径。当存在数字且 form store 中没有该字段时会自动转变成数组。因而如果需要数组为 key 时请使用 string 如:`['1', 'name']`
Expand Down

0 comments on commit a9beed5

Please sign in to comment.