mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
fix:表单项值非string时,部分校验规则一直生效 (#11093)
Co-authored-by: hezhihang <hezhihang@baidu.com>
This commit is contained in:
parent
b93292c100
commit
7d84805605
@ -91,6 +91,16 @@ const makeUrlRegexp = memoize(function (options: any) {
|
||||
return new RegExp(regex, 'i');
|
||||
});
|
||||
|
||||
const valueToString = (value: any) => {
|
||||
return typeof value === 'undefined' || value === null
|
||||
? ''
|
||||
: typeof value === 'string'
|
||||
? value
|
||||
: value instanceof Date
|
||||
? value.toISOString()
|
||||
: JSON.stringify(value);
|
||||
};
|
||||
|
||||
export interface ValidateFn {
|
||||
(
|
||||
values: {[propsName: string]: any},
|
||||
@ -177,9 +187,7 @@ export const validations: {
|
||||
},
|
||||
isLength: function (values, value, length) {
|
||||
// 此方法应该判断文本长度,如果传入数据为number,导致 maxLength 和 maximum 表现一致了,默认转成string
|
||||
if (typeof value === 'number') {
|
||||
value = String(value);
|
||||
}
|
||||
value = valueToString(value);
|
||||
|
||||
return !isExisty(value) || isEmpty(value) || value.length === length;
|
||||
},
|
||||
@ -191,16 +199,14 @@ export const validations: {
|
||||
},
|
||||
maxLength: function (values, value, length) {
|
||||
// 此方法应该判断文本长度,如果传入数据为number,导致 maxLength 和 maximum 表现一致了,默认转成string
|
||||
if (typeof value === 'number') {
|
||||
value = String(value);
|
||||
}
|
||||
value = valueToString(value);
|
||||
|
||||
return !isExisty(value) || value.length <= length;
|
||||
},
|
||||
minLength: function (values, value, length) {
|
||||
// 此方法应该判断文本长度,如果传入数据为number,导致 maxLength 和 maximum 表现一致了,默认转成string
|
||||
if (typeof value === 'number') {
|
||||
value = String(value);
|
||||
}
|
||||
value = valueToString(value);
|
||||
|
||||
return !isExisty(value) || isEmpty(value) || value.length >= length;
|
||||
},
|
||||
isUrlPath: function (values, value, regexp) {
|
||||
|
Loading…
Reference in New Issue
Block a user