mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 05:29:26 +08:00
Merge branch 'main' into next
This commit is contained in:
commit
973038a2e9
@ -119,4 +119,32 @@ describe('string field', () => {
|
||||
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',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -66,4 +66,32 @@ describe('text field', () => {
|
||||
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',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -24,7 +24,13 @@ export class StringField extends Field {
|
||||
|
||||
return {
|
||||
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);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@ -29,7 +29,13 @@ export class TextField extends Field {
|
||||
|
||||
return {
|
||||
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);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user