Merge branch 'next' into develop

This commit is contained in:
nocobase[bot] 2025-04-28 13:17:54 +00:00
commit 1d3013eee6
4 changed files with 70 additions and 2 deletions

View File

@ -119,4 +119,32 @@ describe('string field', () => {
name: 'n1', name: 'n1',
}); });
}); });
it('trim when value is null should be null', async () => {
const collection = db.collection({
name: 'tests',
fields: [{ type: 'string', name: 'name', trim: true }],
});
await db.sync();
const model = await collection.model.create({
name: null,
});
expect(model.toJSON()).toMatchObject({
name: null,
});
});
it('when value is number should be convert to string', async () => {
const collection = db.collection({
name: 'tests',
fields: [{ type: 'string', name: 'name', trim: true }],
});
await db.sync();
const model = await collection.model.create({
name: 123,
});
expect(model.toJSON()).toMatchObject({
name: '123',
});
});
}); });

View File

@ -66,4 +66,32 @@ describe('text field', () => {
name: 'n1', name: 'n1',
}); });
}); });
it('trim when value is null should be null', async () => {
const collection = db.collection({
name: 'tests',
fields: [{ type: 'string', name: 'name', trim: true }],
});
await db.sync();
const model = await collection.model.create({
name: null,
});
expect(model.toJSON()).toMatchObject({
name: null,
});
});
it('when value is number should be convert to string', async () => {
const collection = db.collection({
name: 'tests',
fields: [{ type: 'string', name: 'name', trim: true }],
});
await db.sync();
const model = await collection.model.create({
name: 123,
});
expect(model.toJSON()).toMatchObject({
name: '123',
});
});
}); });

View File

@ -24,7 +24,13 @@ export class StringField extends Field {
return { return {
set(value) { set(value) {
this.setDataValue(name, trim ? value?.trim() : value); if (value == null) {
return value;
}
if (typeof value !== 'string') {
value = value.toString();
}
this.setDataValue(name, trim ? value.trim() : value);
}, },
}; };
} }

View File

@ -29,7 +29,13 @@ export class TextField extends Field {
return { return {
set(value) { set(value) {
this.setDataValue(name, trim ? value?.trim() : value); if (value == null) {
return value;
}
if (typeof value !== 'string') {
value = value.toString();
}
this.setDataValue(name, trim ? value.trim() : value);
}, },
}; };
} }