Browse Source

feat(nc-gui): add fieldLengthValidator

pull/5131/head
Wing-Kam Wong 2 years ago
parent
commit
48188c2e6a
  1. 26
      packages/nc-gui/utils/validation.ts

26
packages/nc-gui/utils/validation.ts

@ -80,6 +80,32 @@ export const fieldRequiredValidator = () => {
}
}
export const fieldLengthValidator = (sqlClientType: string) => {
return {
validator: (rule: any, value: any) => {
const { t } = getI18n().global
// no limit for sqlite but set as 255
let fieldLengthLimit = 255
if (sqlClientType === 'mysql2' || sqlClientType === 'mysql') {
fieldLengthLimit = 64
} else if (sqlClientType === 'pg') {
fieldLengthLimit = 59
} else if (sqlClientType === 'mssql') {
fieldLengthLimit = 128
}
return new Promise((resolve, reject) => {
if (value?.length > fieldLengthLimit) {
reject(new Error(t('msg.error.columnNameExceedsCharacters', { value: fieldLengthLimit })))
}
resolve(true)
})
},
}
}
export const importUrlValidator = {
validator: (rule: any, value: any) => {
return new Promise((resolve, reject) => {

Loading…
Cancel
Save