mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 05:29:26 +08:00
feat(database): add trim option for text field (#6603)
This commit is contained in:
parent
e6a3cbf613
commit
54817e1453
@ -31,6 +31,12 @@ export class TextareaFieldInterface extends CollectionFieldInterface {
|
||||
titleUsable = true;
|
||||
properties = {
|
||||
...defaultProps,
|
||||
trim: {
|
||||
type: 'boolean',
|
||||
'x-content': '{{t("Automatically remove heading and tailing spaces")}}',
|
||||
'x-decorator': 'FormItem',
|
||||
'x-component': 'Checkbox',
|
||||
},
|
||||
};
|
||||
schemaInitialize(schema: ISchema, { block }) {
|
||||
if (['Table', 'Kanban'].includes(block)) {
|
||||
|
@ -52,4 +52,18 @@ describe('text field', () => {
|
||||
});
|
||||
await Test.sync();
|
||||
});
|
||||
|
||||
it('trim', async () => {
|
||||
const collection = db.collection({
|
||||
name: 'tests',
|
||||
fields: [{ type: 'text', name: 'name', trim: true }],
|
||||
});
|
||||
await db.sync();
|
||||
const model = await collection.model.create({
|
||||
name: ' n1\n ',
|
||||
});
|
||||
expect(model.toJSON()).toMatchObject({
|
||||
name: 'n1',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -23,9 +23,20 @@ export class TextField extends Field {
|
||||
this.options.defaultValue = null;
|
||||
}
|
||||
}
|
||||
|
||||
additionalSequelizeOptions() {
|
||||
const { name, trim } = this.options;
|
||||
|
||||
return {
|
||||
set(value) {
|
||||
this.setDataValue(name, trim ? value?.trim() : value);
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export interface TextFieldOptions extends BaseColumnFieldOptions {
|
||||
type: 'text';
|
||||
length?: 'tiny' | 'medium' | 'long';
|
||||
trim?: boolean;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user