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
21a60d5e12
@ -115,9 +115,7 @@ describe('string field', () => {
|
||||
const model = await collection.model.create({
|
||||
name: ' n1\n ',
|
||||
});
|
||||
expect(model.toJSON()).toMatchObject({
|
||||
name: 'n1',
|
||||
});
|
||||
expect(model.get('name')).toBe('n1');
|
||||
});
|
||||
|
||||
it('trim when value is null should be null', async () => {
|
||||
@ -129,9 +127,7 @@ describe('string field', () => {
|
||||
const model = await collection.model.create({
|
||||
name: null,
|
||||
});
|
||||
expect(model.toJSON()).toMatchObject({
|
||||
name: null,
|
||||
});
|
||||
expect(model.get('name')).toBeFalsy();
|
||||
});
|
||||
|
||||
it('when value is number should be convert to string', async () => {
|
||||
@ -143,8 +139,6 @@ describe('string field', () => {
|
||||
const model = await collection.model.create({
|
||||
name: 123,
|
||||
});
|
||||
expect(model.toJSON()).toMatchObject({
|
||||
name: '123',
|
||||
});
|
||||
expect(model.get('name')).toBe('123');
|
||||
});
|
||||
});
|
||||
|
@ -62,9 +62,7 @@ describe('text field', () => {
|
||||
const model = await collection.model.create({
|
||||
name: ' n1\n ',
|
||||
});
|
||||
expect(model.toJSON()).toMatchObject({
|
||||
name: 'n1',
|
||||
});
|
||||
expect(model.get('name')).toBe('n1');
|
||||
});
|
||||
|
||||
it('trim when value is null should be null', async () => {
|
||||
@ -76,9 +74,7 @@ describe('text field', () => {
|
||||
const model = await collection.model.create({
|
||||
name: null,
|
||||
});
|
||||
expect(model.toJSON()).toMatchObject({
|
||||
name: null,
|
||||
});
|
||||
expect(model.get('name')).toBeFalsy();
|
||||
});
|
||||
|
||||
it('when value is number should be convert to string', async () => {
|
||||
@ -90,8 +86,6 @@ describe('text field', () => {
|
||||
const model = await collection.model.create({
|
||||
name: 123,
|
||||
});
|
||||
expect(model.toJSON()).toMatchObject({
|
||||
name: '123',
|
||||
});
|
||||
expect(model.get('name')).toBe('123');
|
||||
});
|
||||
});
|
||||
|
@ -20,12 +20,16 @@ export class StringField extends Field {
|
||||
}
|
||||
|
||||
additionalSequelizeOptions() {
|
||||
const { name, trim } = this.options;
|
||||
const { name, trim, unique } = this.options;
|
||||
|
||||
return {
|
||||
set(value) {
|
||||
if (unique && value === '') {
|
||||
value = null;
|
||||
}
|
||||
if (value == null) {
|
||||
return value;
|
||||
this.setDataValue(name, null);
|
||||
return;
|
||||
}
|
||||
if (typeof value !== 'string') {
|
||||
value = value.toString();
|
||||
|
@ -25,12 +25,16 @@ export class TextField extends Field {
|
||||
}
|
||||
|
||||
additionalSequelizeOptions() {
|
||||
const { name, trim } = this.options;
|
||||
const { name, trim, unique } = this.options;
|
||||
|
||||
return {
|
||||
set(value) {
|
||||
if (unique && value === '') {
|
||||
value = null;
|
||||
}
|
||||
if (value == null) {
|
||||
return value;
|
||||
this.setDataValue(name, null);
|
||||
return;
|
||||
}
|
||||
if (typeof value !== 'string') {
|
||||
value = value.toString();
|
||||
|
Loading…
x
Reference in New Issue
Block a user