UNPKG

653 BJavaScriptView Raw
1/**
2 @demo
3 // 1.导入
4 import onFormFieldChange from "@script/onFormFieldChange";
5 // 2.创建方法
6 const onFieldsChange = onFormFieldChange("type", value => {
7 console.log(value);
8 });
9 // 3.绑定到 Form
10 <Form onFieldsChange={onFieldsChange}>...</Form>
11*/
12/**
13 * Form表单字段更改
14 * @param {String} key
15 * @param {Function} callback
16 * @return Function
17 */
18const onFieldChange = (key, callback) => changedFields => {
19 if (changedFields.length > 0) {
20 const field = changedFields[0];
21 if (field.name.includes(key)) {
22 const value = field.value;
23 callback(value);
24 }
25 }
26};
27
28export default onFieldChange;