Merge branch 'main' into next

This commit is contained in:
GitHub Actions Bot 2024-08-07 07:31:23 +00:00
commit d386cd4595

View File

@ -8,15 +8,39 @@
*/
import { ISchema } from '@formily/react';
import { defaultProps, operators, unique, primaryKey } from './properties';
import { i18n } from '../../i18n';
import { isArr, isEmpty, isValid } from '@formily/shared';
import { registerValidateRules } from '@formily/validator';
import { CollectionFieldInterface } from '../../data-source/collection-field-interface/CollectionFieldInterface';
import { i18n } from '../../i18n';
import { defaultProps, operators, primaryKey, unique } from './properties';
const isValidateEmpty = (value: any) => {
if (isArr(value)) {
for (let i = 0; i < value.length; i++) {
if (isValid(value[i])) return false;
}
return true;
} else {
//compat to draft-js
if (value?.getCurrentContent) {
/* istanbul ignore next */
return !value.getCurrentContent()?.hasText();
}
return isEmpty(value);
}
};
registerValidateRules({
username(value) {
return /^[^@.<>"'/]{1,50}$/.test(value) || i18n.t('Must be 1-50 characters in length (excluding @.<>"\'/)');
},
required(value, rule) {
if (rule.required === false) return '';
if (typeof value === 'string') {
value = value.trim();
}
return isValidateEmpty(value) ? rule.message : '';
},
});
export class InputFieldInterface extends CollectionFieldInterface {