Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

name validation

Ramesh Manec94bddc2513c
diff --git a/packages/nc-gui/components/smartsheet/expanded-form/Detached.vue b/packages/nc-gui/components/smartsheet/expanded-form/Detached.vue
index 9d14b8e84b..6436351302 100644
--- a/packages/nc-gui/components/smartsheet/expanded-form/Detached.vue
+++ b/packages/nc-gui/components/smartsheet/expanded-form/Detached.vue
@@ -22,6 +22,8 @@ const shouldClose = (isVisible: boolean, i: number) => {
:template-mode="state.templateMode"
:template-name="state.templateName"
:blueprint-mode="state.blueprintMode"
+ :existing-template-names="state.existingTemplateNames"
+ :editing-template-id="state.editingTemplateId"
:new-record-submit-btn-text="state.newRecordSubmitBtnText"
:new-record-header="state.newRecordHeader"
@update:model-value="shouldClose($event, i)"
diff --git a/packages/nc-gui/components/smartsheet/expanded-form/index.vue b/packages/nc-gui/components/smartsheet/expanded-form/index.vue
index b55acf9079..134ac3a475 100644
--- a/packages/nc-gui/components/smartsheet/expanded-form/index.vue
+++ b/packages/nc-gui/components/smartsheet/expanded-form/index.vue
@@ -24,6 +24,8 @@ interface Props {
templateMode?: boolean
templateName?: string
blueprintMode?: boolean
+ existingTemplateNames?: string[]
+ editingTemplateId?: string
expandForm?: (row: Row) => void
maintainDefaultViewOrder?: boolean
allowNullFieldIds?: string[]
@@ -125,6 +127,14 @@ const isSaving = ref(false)
// Template mode: editable template name in the header
const editableTemplateName = ref(props.templateName || '')
+// Template name duplicate detection
+const isDuplicateTemplateName = computed(() => {
+ if (!props.templateMode || !props.existingTemplateNames?.length) return false
+ const trimmed = editableTemplateName.value.trim().toLowerCase()
+ if (!trimmed) return false
+ return props.existingTemplateNames.some((name) => name.trim().toLowerCase() === trimmed)
+})
+
const expandedFormStore = useProvideExpandedFormStore(
activeMeta,
row,
@@ -267,8 +277,10 @@ const isLTARChanged = computed(() => {
})
const isSaveRecordBtnDisabled = computed(() => {
- // In template/blueprint mode, always allow saving (even empty)
- if (props.templateMode || props.blueprintMode) return false
+ // In template mode, disable if duplicate name
+ if (props.templateMode) return isDuplicateTemplateName.value
+ // In blueprint mode, always allow saving
+ if (props.blueprintMode) return false
return changedColumns.value.size === 0 && !isUnsavedFormExist.value && !isLTARChanged.value
})
@@ -319,6 +331,11 @@ const save = async () => {
isSaving.value = false
return
}
+ if (isDuplicateTemplateName.value) {
+ message.toast('A template with this name already exists')
+ isSaving.value = false
+ return
+ }
isUnsavedFormExist.value = false
isExpanded.value = false
emits('createdRecord', {
@@ -960,14 +977,18 @@ export default {
</div>
<div
v-if="templateMode"
- class="flex items-center truncate font-bold text-nc-content-gray text-xl overflow-hidden"
+ class="flex flex-col truncate overflow-hidden"
>
<input
ref="templateNameInputRef"
v-model="editableTemplateName"
- class="bg-transparent border-none outline-none font-bold text-xl text-nc-content-gray w-full placeholder-gray-300"
+ class="bg-transparent border-none outline-none font-bold text-xl w-full placeholder-gray-300"
+ :class="isDuplicateTemplateName ? 'text-red-500' : 'text-nc-content-gray'"
placeholder="Enter template name..."
/>
+ <span v-if="isDuplicateTemplateName" class="text-red-500 text-[11px] pl-0.5">
+ A template with this name already exists
+ </span>
</div>
<div
v-else-if="row.rowMeta?.new || props.newRecordHeader"
diff --git a/packages/nc-gui/components/smartsheet/toolbar/RecordTemplatesButton.vue b/packages/nc-gui/components/smartsheet/toolbar/RecordTemplatesButton.vue
index 6f5b1d3e50..68f40d8ca0 100644
--- a/packages/nc-gui/components/smartsheet/toolbar/RecordTemplatesButton.vue
+++ b/packages/nc-gui/components/smartsheet/toolbar/RecordTemplatesButton.vue
@@ -174,6 +174,15 @@ const saveTemplate = async (rowData: Record<string, any>, editingTmpl: TemplateT
// Extract template name from the special _templateName field
const title = rowData._templateName?.trim() || `Record Template #${nextTemplateNumber.value}`
+ // Enforce unique template name (client-side check)
+ const duplicate = templates.value.find(
+ (t) => t.title?.trim().toLowerCase() === title.toLowerCase() && t.id !== editingTmpl?.id,
+ )
+ if (duplicate) {
+ message.toast(`A template with the name "${title}" already exists`)
+ return
+ }
+
// Extract LTAR state (linked records) before filtering
const ltarState = rowData._ltarState || {}
@@ -230,6 +239,11 @@ const openTemplateForm = (editingTmpl: TemplateType | null = null) => {
: { fields: {}, ltarState: {} }
const templateName = editingTmpl?.title || `Record Template #${nextTemplateNumber.value}`
+ // Collect existing template names for duplicate validation (exclude current template when editing)
+ const existingTemplateNames = templates.value
+ .filter((t) => t.id !== editingTmpl?.id)
+ .map((t) => t.title || '')
+
openExpandedForm({
isOpen: true,
row: {
@@ -243,6 +257,7 @@ const openTemplateForm = (editingTmpl: TemplateType | null = null) => {
skipReload: true,
templateMode: true,
templateName,
+ existingTemplateNames,
newRecordSubmitBtnText: editingTmpl ? 'Save Template' : 'Create Template',
createdRecord: async (rowData: Record<string, any>) => {
await saveTemplate(rowData, editingTmpl)
diff --git a/packages/nc-gui/composables/useExpandedFormDetached/index.ts b/packages/nc-gui/composables/useExpandedFormDetached/index.ts
index 6bf25f3800..9fd674c3ca 100644
--- a/packages/nc-gui/composables/useExpandedFormDetached/index.ts
+++ b/packages/nc-gui/composables/useExpandedFormDetached/index.ts
@@ -18,6 +18,8 @@ export interface UseExpandedFormDetachedProps {
'blueprintMode'?: boolean
'newRecordSubmitBtnText'?: string
'newRecordHeader'?: string
+ 'existingTemplateNames'?: string[]
+ 'editingTemplateId'?: string
'createdRecord'?: (row: Row['row']) => void
}
diff --git a/packages/nocodb/src/services/record-templates/record-templates.service.ts b/packages/nocodb/src/services/record-templates/record-templates.service.ts
index 7103433f2f..6938d83058 100644
--- a/packages/nocodb/src/services/record-templates/record-templates.service.ts
+++ b/packages/nocodb/src/services/record-templates/record-templates.service.ts
@@ -61,6 +61,14 @@ export class RecordTemplatesService {
// Validate template data structure
this.validateTemplateData(param.body.template_data);
+ // Enforce unique template name per table
+ await this.ensureUniqueTitle(
+ param.context,
+ param.baseId,
+ param.sourceId,
+ param.body.title,
+ );
+
const template = await RecordTemplate.insert(param.context, {
base_id: param.baseId,
source_id: param.sourceId,
@@ -99,6 +107,17 @@ export class RecordTemplatesService {
this.validateTemplateData(param.body.template_data);
}
+ // Enforce unique template name per table (if title is being changed)
+ if (param.body.title && param.body.title !== existingTemplate.title) {
+ await this.ensureUniqueTitle(
+ param.context,
+ existingTemplate.base_id,
+ existingTemplate.source_id,
+ param.body.title,
+ param.templateId,
+ );
+ }
+
const template = await RecordTemplate.update(
param.context,
param.templateId,
@@ -173,6 +192,35 @@ export class RecordTemplatesService {
return updatedTemplate;
}
+ /**
+ * Ensures no other template in the same table has the same title (case-insensitive).
+ * Optionally excludes a specific template (for updates).
+ */
+ private async ensureUniqueTitle(
+ context: NcContext,
+ baseId: string,
+ sourceId: string,
+ title: string,
+ excludeTemplateId?: string,
+ ) {
+ const existing = await RecordTemplate.list(context, {
+ base_id: baseId,
+ source_id: sourceId,
+ });
+
+ const duplicate = existing.find(
+ (t) =>
+ t.title?.trim().toLowerCase() === title.trim().toLowerCase() &&
+ t.id !== excludeTemplateId,
+ );
+
+ if (duplicate) {
+ NcError.badRequest(
+ `A template with the name "${title.trim()}" already exists`,
+ );
+ }
+ }
+
/**
* Validates template data structure.
* Template data format: { fields: Record<string, any>, ltarState?: Record<string, any> }