Browse Source

Merge pull request #6962 from nocodb/fix/trim-select

fix: trailing space handling for select options
pull/6972/head
Raju Udava 1 year ago committed by GitHub
parent
commit
8d66f06c8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      packages/nc-gui/components/cell/MultiSelect.vue
  2. 4
      packages/nc-gui/components/cell/SingleSelect.vue
  3. 10
      packages/nocodb/src/services/columns.service.ts

8
packages/nc-gui/components/cell/MultiSelect.vue

@ -144,14 +144,14 @@ const selectedTitles = computed(() =>
} }
return 0 return 0
}) })
: modelValue.split(',').map((el) => el.trim()) : modelValue.split(',')
: modelValue.map((el) => el.trim()) : modelValue
: [], : [],
) )
onMounted(() => { onMounted(() => {
selectedIds.value = selectedTitles.value.flatMap((el) => { selectedIds.value = selectedTitles.value.flatMap((el) => {
const item = options.value.find((op) => op.title === el) const item = options.value.find((op) => op.title === el || op.title === el?.trim())
const itemIdOrTitle = item?.id || item?.title const itemIdOrTitle = item?.id || item?.title
if (itemIdOrTitle) { if (itemIdOrTitle) {
return [itemIdOrTitle] return [itemIdOrTitle]
@ -165,7 +165,7 @@ watch(
() => modelValue, () => modelValue,
() => { () => {
selectedIds.value = selectedTitles.value.flatMap((el) => { selectedIds.value = selectedTitles.value.flatMap((el) => {
const item = options.value.find((op) => op.title === el) const item = options.value.find((op) => op.title === el || op.title === el?.trim())
if (item && (item.id || item.title)) { if (item && (item.id || item.title)) {
return [(item.id || item.title)!] return [(item.id || item.title)!]
} }

4
packages/nc-gui/components/cell/SingleSelect.vue

@ -104,7 +104,7 @@ const hasEditRoles = computed(() => isUIAllowed('dataEdit'))
const editAllowed = computed(() => (hasEditRoles.value || isForm.value) && active.value) const editAllowed = computed(() => (hasEditRoles.value || isForm.value) && active.value)
const vModel = computed({ const vModel = computed({
get: () => tempSelectedOptState.value ?? modelValue?.trim(), get: () => tempSelectedOptState.value ?? modelValue,
set: (val) => { set: (val) => {
if (val && isNewOptionCreateEnabled.value && (options.value ?? []).every((op) => op.title !== val)) { if (val && isNewOptionCreateEnabled.value && (options.value ?? []).every((op) => op.title !== val)) {
tempSelectedOptState.value = val tempSelectedOptState.value = val
@ -259,7 +259,7 @@ const handleClose = (e: MouseEvent) => {
useEventListener(document, 'click', handleClose, true) useEventListener(document, 'click', handleClose, true)
const selectedOpt = computed(() => { const selectedOpt = computed(() => {
return options.value.find((o) => o.value === vModel.value) return options.value.find((o) => o.value === vModel.value || o.value === vModel.value?.trim())
}) })
</script> </script>

10
packages/nocodb/src/services/columns.service.ts

@ -356,12 +356,10 @@ export class ColumnsService {
}), }),
); );
const data = await baseModel.execAndParse( const data = await sqlClient.raw('SELECT DISTINCT ?? FROM ??', [
sqlClient.raw('SELECT DISTINCT ?? FROM ??', [ column.column_name,
column.column_name, baseModel.getTnPath(table.table_name),
baseModel.getTnPath(table.table_name), ]);
]),
);
if (data.length) { if (data.length) {
const existingOptions = colBody.colOptions.options.map( const existingOptions = colBody.colOptions.options.map(

Loading…
Cancel
Save