mirror of
https://github.com/nocodb/nocodb.git
synced 2026-05-03 15:36:53 +00:00
* fix(nc-gui): introduce header icon in gallery view card and update style * fix(nc-gui): field modal width issue if it is rich text * fix(nc-gui): hide longtext expanded icon on gallery & kanban view card hove * fix(nc-gui): date field alignment issue * fix(nc-gui): udpate kanban view card * fix(nc-gui): udpate gallery & kanban view card display value style * fix(nocodb): hide cover image in new gallery, kanban view if it is not pv column * feat(nc-gui): change cover image object fit property change support * fix(nc-gui): virtual cell card value alignment issue * fix(nc-gui): gallery view card image navigation issue * fix(nc-gui): gallerym, kanban card cover image dots navigation overflow issue * fix(nocodb): use optional chaining to access nested variable * chore(nc-gui): lint * fix(nc-gui): long text max line shuld be 4 in card * test: update open expanded form in gallery test * fix(nc-gui): add empty card in gallery view if cards length is less than 4 * fix(nc-gui): update gallery view card min width * fix(nocodb): small changes * fix(nc-gui): review changes * fix(nc-gui): add input shadow effect * fix(nc-gui): update card image navigation buttons icon * fix(nc-gui): udpate gallery view bg color * fix(nc-gui): update email, url, phone cell height from card * fix(nc-gui): update isEmptyRow function logic * fix(nc-gui): some review changes * fix(nc-gui): card display value color * fix(nc-gui): udpate gallery view card min width * fix(nc-gui): update card shadow & border on hover * fix(nc-gui): update gallery loader card width * fix(nc-gui): add min height for card image * chore(nc-gui): lint * fix(nc-gui): card rich text height * fix(nc-gui): align record count in right side in gallery view * fix(nc-gui): review changes * fix(nc-gui): shared view show & hide field issue * chore(nc-gui): lint * fix(nc-gui): link record test fail issue
156 lines
3.9 KiB
TypeScript
156 lines
3.9 KiB
TypeScript
import type { RuleObject } from 'ant-design-vue/es/form'
|
|
import isMobilePhone from 'validator/lib/isMobilePhone'
|
|
import { StringValidationType, UITypes } from 'nocodb-sdk'
|
|
import type { ColumnType, Validation } from 'nocodb-sdk'
|
|
import { getI18n } from '../plugins/a.i18n'
|
|
|
|
export const formEmailValidator = (val: Validation) => {
|
|
return {
|
|
validator: (_rule: RuleObject, value: any) => {
|
|
return new Promise((resolve, reject) => {
|
|
const { t } = getI18n().global
|
|
|
|
if (value && !validateEmail(value)) {
|
|
return reject(val.message || t('msg.error.invalidEmail'))
|
|
}
|
|
return resolve(true)
|
|
})
|
|
},
|
|
}
|
|
}
|
|
|
|
export const formPhoneNumberValidator = (val: Validation) => {
|
|
return {
|
|
validator: (_rule: RuleObject, value: any) => {
|
|
return new Promise((resolve, reject) => {
|
|
const { t } = getI18n().global
|
|
|
|
if (value && !isMobilePhone(value)) {
|
|
return reject(val.message || t('msg.invalidPhoneNumber'))
|
|
}
|
|
return resolve(true)
|
|
})
|
|
},
|
|
}
|
|
}
|
|
|
|
export const formUrlValidator = (val: Validation) => {
|
|
return {
|
|
validator: (_rule: RuleObject, value: any) => {
|
|
return new Promise((resolve, reject) => {
|
|
const { t } = getI18n().global
|
|
|
|
if (value && !isValidURL(value)) {
|
|
return reject(val.message || t('msg.error.invalidURL'))
|
|
}
|
|
return resolve(true)
|
|
})
|
|
},
|
|
}
|
|
}
|
|
|
|
export const formNumberInputValidator = (cal: ColumnType) => {
|
|
return {
|
|
validator: (_rule: RuleObject, value: any) => {
|
|
return new Promise((resolve, reject) => {
|
|
const { t } = getI18n().global
|
|
|
|
if (value && value !== '-' && !(cal.uidt === UITypes.Number ? /^-?\d+$/.test(value) : /^-?\d*\.?\d+$/.test(value))) {
|
|
return reject(t('msg.plsEnterANumber'))
|
|
}
|
|
return resolve(true)
|
|
})
|
|
},
|
|
}
|
|
}
|
|
|
|
export const requiredFieldValidatorFn = (value: unknown) => {
|
|
value = unref(value)
|
|
if (Array.isArray(value)) return !!value.length
|
|
|
|
if (value === undefined || value === null) {
|
|
return false
|
|
}
|
|
|
|
if (value === false) {
|
|
return true
|
|
}
|
|
|
|
if (typeof value === 'object') {
|
|
if (Object.keys(value).length > 0) {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
return !!String(value).length
|
|
}
|
|
|
|
export const isEmptyValidatorValue = (v: Validation) => {
|
|
if (v.type === StringValidationType.Regex) {
|
|
return v.type && typeof v.regex === 'string' ? !v.regex.trim() : v.regex === null
|
|
} else if (v.type && v.value !== undefined) {
|
|
return v.type && typeof v.value === 'string' ? !v.value.trim() : v.value === null
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
export const extractFieldValidator = (_validators: Validation[], element: ColumnType) => {
|
|
const rules: RuleObject[] = []
|
|
|
|
// Add column default validators
|
|
if ([UITypes.Number, UITypes.Currency, UITypes.Percent].includes(element.uidt)) {
|
|
rules.push(formNumberInputValidator(element))
|
|
}
|
|
|
|
switch (element.uidt) {
|
|
case UITypes.Email: {
|
|
if (parseProp(element.meta).validate) {
|
|
rules.push(
|
|
formEmailValidator({
|
|
type: StringValidationType.Email,
|
|
}),
|
|
)
|
|
}
|
|
break
|
|
}
|
|
case UITypes.PhoneNumber: {
|
|
if (parseProp(element.meta).validate) {
|
|
rules.push(
|
|
formPhoneNumberValidator({
|
|
type: StringValidationType.PhoneNumber,
|
|
}),
|
|
)
|
|
}
|
|
break
|
|
}
|
|
case UITypes.URL: {
|
|
if (parseProp(element.meta).validate) {
|
|
rules.push(
|
|
formUrlValidator({
|
|
type: StringValidationType.Url,
|
|
}),
|
|
)
|
|
}
|
|
break
|
|
}
|
|
}
|
|
|
|
return rules
|
|
}
|
|
|
|
export const getValidFieldName = (title: string, uniqueFieldNames: Set<string>) => {
|
|
title = title.replace(/\./g, '_')
|
|
let counter = 1
|
|
|
|
let newTitle = title
|
|
while (uniqueFieldNames.has(newTitle)) {
|
|
newTitle = `${title}_${counter}`
|
|
counter++
|
|
}
|
|
uniqueFieldNames.add(newTitle)
|
|
return newTitle
|
|
}
|