mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 08:55:33 +00:00
Merge branch 'main' into next
This commit is contained in:
commit
d386cd4595
@ -8,15 +8,39 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { ISchema } from '@formily/react';
|
import { ISchema } from '@formily/react';
|
||||||
import { defaultProps, operators, unique, primaryKey } from './properties';
|
import { isArr, isEmpty, isValid } from '@formily/shared';
|
||||||
import { i18n } from '../../i18n';
|
|
||||||
import { registerValidateRules } from '@formily/validator';
|
import { registerValidateRules } from '@formily/validator';
|
||||||
import { CollectionFieldInterface } from '../../data-source/collection-field-interface/CollectionFieldInterface';
|
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({
|
registerValidateRules({
|
||||||
username(value) {
|
username(value) {
|
||||||
return /^[^@.<>"'/]{1,50}$/.test(value) || i18n.t('Must be 1-50 characters in length (excluding @.<>"\'/)');
|
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 {
|
export class InputFieldInterface extends CollectionFieldInterface {
|
||||||
|
Loading…
Reference in New Issue
Block a user