Merge branch 'next' into develop

This commit is contained in:
nocobase[bot] 2025-04-01 05:25:53 +00:00
commit 97c310e9f2
5 changed files with 34 additions and 2 deletions

View File

@ -62,6 +62,12 @@ export class InputFieldInterface extends CollectionFieldInterface {
hasDefaultValue = true; hasDefaultValue = true;
properties = { properties = {
...defaultProps, ...defaultProps,
trim: {
type: 'boolean',
'x-content': '{{t("Automatically remove heading and tailing spaces")}}',
'x-decorator': 'FormItem',
'x-component': 'Checkbox',
},
layout: { layout: {
type: 'void', type: 'void',
title: '{{t("Index")}}', title: '{{t("Index")}}',

View File

@ -259,6 +259,7 @@
"Parent collection fields": "父表字段", "Parent collection fields": "父表字段",
"Basic": "基本类型", "Basic": "基本类型",
"Single line text": "单行文本", "Single line text": "单行文本",
"Automatically remove heading and tailing spaces": "自动去除首尾空白字符",
"Long text": "多行文本", "Long text": "多行文本",
"Phone": "手机号码", "Phone": "手机号码",
"Email": "电子邮箱", "Email": "电子邮箱",

View File

@ -33,7 +33,7 @@ import { RemoteSelect, RemoteSelectProps } from '../remote-select';
import useServiceOptions, { useAssociationFieldContext } from './hooks'; import useServiceOptions, { useAssociationFieldContext } from './hooks';
const removeIfKeyEmpty = (obj, filterTargetKey) => { const removeIfKeyEmpty = (obj, filterTargetKey) => {
if (!obj || typeof obj !== 'object' || !filterTargetKey) return obj; if (!obj || typeof obj !== 'object' || !filterTargetKey || Array.isArray(obj)) return obj;
return !obj[filterTargetKey] ? null : obj; return !obj[filterTargetKey] ? null : obj;
}; };

View File

@ -105,4 +105,18 @@ describe('string field', () => {
name2: 'n2111', name2: 'n2111',
}); });
}); });
it('trim', async () => {
const collection = db.collection({
name: 'tests',
fields: [{ type: 'string', name: 'name', trim: true }],
});
await db.sync();
const model = await collection.model.create({
name: ' n1\n ',
});
expect(model.toJSON()).toMatchObject({
name: 'n1',
});
});
}); });

View File

@ -8,7 +8,7 @@
*/ */
import { DataTypes } from 'sequelize'; import { DataTypes } from 'sequelize';
import { BaseColumnFieldOptions, Field } from './field'; import { BaseColumnFieldOptions, Field, FieldContext } from './field';
export class StringField extends Field { export class StringField extends Field {
get dataType() { get dataType() {
@ -18,9 +18,20 @@ export class StringField extends Field {
return DataTypes.STRING; return DataTypes.STRING;
} }
additionalSequelizeOptions() {
const { name, trim } = this.options;
return {
set(value) {
this.setDataValue(name, trim ? value?.trim() : value);
},
};
}
} }
export interface StringFieldOptions extends BaseColumnFieldOptions { export interface StringFieldOptions extends BaseColumnFieldOptions {
type: 'string'; type: 'string';
length?: number; length?: number;
trim?: boolean;
} }