From 3ce82329fc33e00f9e800a29572a82d971e9e0db Mon Sep 17 00:00:00 2001 From: Pranav C Date: Mon, 1 Aug 2022 11:40:11 +0530 Subject: [PATCH] feat(gui-v2): duplicate column name validation Signed-off-by: Pranav C --- .../composables/useColumnCreateStore.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/nc-gui-v2/composables/useColumnCreateStore.ts b/packages/nc-gui-v2/composables/useColumnCreateStore.ts index 34a0db6532..19fb681908 100644 --- a/packages/nc-gui-v2/composables/useColumnCreateStore.ts +++ b/packages/nc-gui-v2/composables/useColumnCreateStore.ts @@ -45,6 +45,24 @@ const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState required: true, message: 'Column name is required', }, + // validation for unique column name + { + validator: (rule: any, value: any, callback: (errMsg?: string) => void) => { + if ( + meta.value?.columns?.some( + (c) => + c.id !== formState.value.id && // ignore current column + // compare against column_name and title + ((value || '').toLowerCase() === (c.column_name || '').toLowerCase() || + (value || '').toLowerCase() === (c.title || '').toLowerCase()), + ) + ) { + callback('Duplicate column name') + } + + callback() + }, + }, ], uidt: [ {