diff --git a/packages/nc-gui/composables/useColumnCreateStore.ts b/packages/nc-gui/composables/useColumnCreateStore.ts index addb21c1d5..9816b4e183 100644 --- a/packages/nc-gui/composables/useColumnCreateStore.ts +++ b/packages/nc-gui/composables/useColumnCreateStore.ts @@ -193,6 +193,10 @@ const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState formState.value.table_name = meta.value?.table_name // formState.value.title = formState.value.column_name if (column.value) { + // reset column validation if column is not to be validated + if (!columnToValidate.includes(formState.value.uidt)) { + formState.value.validate = '' + } await $api.dbTableColumn.update(column.value?.id as string, formState.value) // Column updated message.success(t('msg.success.columnUpdated')) diff --git a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts index 07e9d93363..f2c7ba99c2 100644 --- a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts +++ b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts @@ -2236,11 +2236,13 @@ class BaseModelSqlv2 { for (let i = 0; i < this.model.columns.length; ++i) { const column = this.model.columns[i]; // skip validation if `validate` is undefined or false - if (!column?.meta?.validate) continue; + if (!column?.meta?.validate && !column?.validate) continue; const validate = column.getValidators(); const cn = column.column_name; + const columnTitle = column.title; if (!validate) continue; + const { func, msg } = validate; for (let j = 0; j < func.length; ++j) { const fn = @@ -2249,17 +2251,17 @@ class BaseModelSqlv2 { ? customValidators[func[j]] : Validator[func[j]] : func[j]; + const columnValue = columns?.[cn] || columns?.[columnTitle]; const arg = - typeof func[j] === 'string' ? columns[cn] + '' : columns[cn]; + typeof func[j] === 'string' ? columnValue + '' : columnValue; if ( - columns[cn] !== null && - columns[cn] !== undefined && - columns[cn] !== '' && - cn in columns && + ![null, undefined, ''].includes(columnValue) && !(fn.constructor.name === 'AsyncFunction' ? await fn(arg) : fn(arg)) ) { NcError.badRequest( - msg[j].replace(/\{VALUE}/g, columns[cn]).replace(/\{cn}/g, cn) + msg[j] + .replace(/\{VALUE}/g, columnValue) + .replace(/\{cn}/g, columnTitle) ); } }