@hi-ui/form 4.3.2 → 4.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/lib/cjs/use-form-field.js +14 -1
- package/lib/esm/use-form-field.js +15 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @hi-ui/form
|
|
2
2
|
|
|
3
|
+
## 4.3.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#3277](https://github.com/XiaoMi/hiui/pull/3277) [`93df0aaff`](https://github.com/XiaoMi/hiui/commit/93df0aafff09be59faeb4bad0ceea57a00df5ccf) Thanks [@zyprepare](https://github.com/zyprepare)! - fix(form): 处理规则消息为空的情况,将其设置为 undefined (#3276)
|
|
8
|
+
|
|
9
|
+
- [#3275](https://github.com/XiaoMi/hiui/pull/3275) [`b2b66a9e7`](https://github.com/XiaoMi/hiui/commit/b2b66a9e73a1a92d6b0604dc2ad711895154e518) Thanks [@zyprepare](https://github.com/zyprepare)! - fix(form): 优化 valueType 为 number 情况下的校验逻辑 (#3274)
|
|
10
|
+
|
|
3
11
|
## 4.3.2
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -63,6 +63,9 @@ var useFormField = function useFormField(props) {
|
|
|
63
63
|
// TODO: rules 处理成 Async Validate 的指定结构
|
|
64
64
|
var fieldMD5 = index.stringify(field);
|
|
65
65
|
var modifiedFieldRules = fieldRules.map(function (rule) {
|
|
66
|
+
if (rule.message === null || rule.message === '') {
|
|
67
|
+
rule.message = undefined;
|
|
68
|
+
}
|
|
66
69
|
// 重写 rule 的 validator 函数,正则匹配 validatorRule 中的 field 和 fullField,消除 field 和 fullField 中的双引号
|
|
67
70
|
// issue:https://github.com/XiaoMi/hiui/issues/2931
|
|
68
71
|
if (rule.validator) {
|
|
@@ -79,7 +82,17 @@ var useFormField = function useFormField(props) {
|
|
|
79
82
|
} else return Object.assign({}, rule);
|
|
80
83
|
});
|
|
81
84
|
var validater = new Validater__default["default"]((_Validater = {}, _Validater[fieldMD5] = modifiedFieldRules, _Validater));
|
|
82
|
-
|
|
85
|
+
var valueToValidate = value;
|
|
86
|
+
if (valueType === 'number') {
|
|
87
|
+
if (typeAssertion.isNullish(value) || value === '') {
|
|
88
|
+
valueToValidate = value;
|
|
89
|
+
} else if (isNaN(value)) {
|
|
90
|
+
valueToValidate = value;
|
|
91
|
+
} else {
|
|
92
|
+
valueToValidate = Number(value);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return validater.validate((_validater$validate = {}, _validater$validate[fieldMD5] = valueToValidate, _validater$validate), {
|
|
83
96
|
firstFields: true
|
|
84
97
|
});
|
|
85
98
|
}, [fieldRules, field, valueType]);
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { useMemo, useCallback, useEffect } from 'react';
|
|
11
11
|
import { useFormContext } from './context.js';
|
|
12
|
-
import { isArrayNonEmpty } from '@hi-ui/type-assertion';
|
|
12
|
+
import { isArrayNonEmpty, isNullish } from '@hi-ui/type-assertion';
|
|
13
13
|
import Validater from 'async-validator';
|
|
14
14
|
import { normalizeArray } from '@hi-ui/array-utils';
|
|
15
15
|
import { stringify, isValidField } from './utils/index.js';
|
|
@@ -51,6 +51,9 @@ var useFormField = function useFormField(props) {
|
|
|
51
51
|
// TODO: rules 处理成 Async Validate 的指定结构
|
|
52
52
|
var fieldMD5 = stringify(field);
|
|
53
53
|
var modifiedFieldRules = fieldRules.map(function (rule) {
|
|
54
|
+
if (rule.message === null || rule.message === '') {
|
|
55
|
+
rule.message = undefined;
|
|
56
|
+
}
|
|
54
57
|
// 重写 rule 的 validator 函数,正则匹配 validatorRule 中的 field 和 fullField,消除 field 和 fullField 中的双引号
|
|
55
58
|
// issue:https://github.com/XiaoMi/hiui/issues/2931
|
|
56
59
|
if (rule.validator) {
|
|
@@ -67,7 +70,17 @@ var useFormField = function useFormField(props) {
|
|
|
67
70
|
} else return Object.assign({}, rule);
|
|
68
71
|
});
|
|
69
72
|
var validater = new Validater((_Validater = {}, _Validater[fieldMD5] = modifiedFieldRules, _Validater));
|
|
70
|
-
|
|
73
|
+
var valueToValidate = value;
|
|
74
|
+
if (valueType === 'number') {
|
|
75
|
+
if (isNullish(value) || value === '') {
|
|
76
|
+
valueToValidate = value;
|
|
77
|
+
} else if (isNaN(value)) {
|
|
78
|
+
valueToValidate = value;
|
|
79
|
+
} else {
|
|
80
|
+
valueToValidate = Number(value);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return validater.validate((_validater$validate = {}, _validater$validate[fieldMD5] = valueToValidate, _validater$validate), {
|
|
71
84
|
firstFields: true
|
|
72
85
|
});
|
|
73
86
|
}, [fieldRules, field, valueType]);
|