Skip to content

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

feat: add icon support for dynamic form select input option

Ramesh Manec3b853bfaf19
diff --git a/packages/nc-gui/components/nc/form-builder/index.vue b/packages/nc-gui/components/nc/form-builder/index.vue
index 425ec4c13c..05d00f1d62 100644
--- a/packages/nc-gui/components/nc/form-builder/index.vue
+++ b/packages/nc-gui/components/nc/form-builder/index.vue
@@ -314,7 +314,7 @@ watch(
</template>
<template v-else-if="field.type === FormBuilderInputType.Textarea">
<a-textarea
- class="!w-full !rounded-lg !min-h-[90px] max-h-[500px] nc-scrollbar-thin"
+ class="!w-full !rounded-lg !text-sm !min-h-[90px] max-h-[500px] nc-scrollbar-thin"
size="large"
hide-details
:value="deepReference(field.model)"
@@ -350,14 +350,39 @@ watch(
<NcSelect
:disabled="disabled"
:value="getSelectValue(field)"
- :options="field.fetchOptionsKey ? getFieldOptions(field.model) : field.options"
:mode="selectMode(field)"
:max-tag-count="field.selectMode === 'singleWithInput' ? 1 : undefined"
show-search
:placeholder="field.placeholder"
:loading="field.fetchOptionsKey && getIsLoadingFieldOptions(field.model)"
@update:value="handleSelectChange(field, $event)"
- />
+ >
+ <a-select-option
+ v-for="option in field.fetchOptionsKey ? getFieldOptions(field.model) : field.options"
+ :key="option.value"
+ :value="option.value"
+ >
+ <div class="w-full flex gap-2 items-center" :data-testid="option.value">
+ <GeneralIcon v-if="option.icon" :icon="option.icon" class="flex-none h-4 w-4" />
+ <NcTooltip class="flex-1 truncate min-w-0" show-on-truncate-only>
+ <template #title>
+ {{ option.label }}
+ </template>
+ {{ option.label }}
+ </NcTooltip>
+ <component
+ :is="iconMap.check"
+ v-if="
+ ncIsArray(getSelectValue(field))
+ ? getSelectValue(field).includes(option.value)
+ : getSelectValue(field) === option.value
+ "
+ id="nc-selected-item-icon"
+ class="text-nc-content-brand w-4 h-4"
+ />
+ </div>
+ </a-select-option>
+ </NcSelect>
</NcFormBuilderInputMountedWrapper>
</template>
<template v-else-if="field.type === FormBuilderInputType.Switch">
@@ -405,7 +430,7 @@ watch(
>
<div class="w-full flex gap-2 items-center" :data-testid="integration.title">
<GeneralIntegrationIcon v-if="integration?.sub_type" :type="integration.sub_type" />
- <NcTooltip class="flex-1 truncate">
+ <NcTooltip class="flex-1 truncate" show-on-truncate-only>
<template #title>
{{ integration.title }}
</template>
@@ -415,7 +440,7 @@ watch(
:is="iconMap.check"
v-if="formState.fk_integration_id === integration.id"
id="nc-selected-item-icon"
- class="text-primary w-4 h-4"
+ class="text-nc-content-brand w-4 h-4"
/>
</div>
</a-select-option>
diff --git a/packages/nocodb-sdk/src/lib/formBuilder/index.ts b/packages/nocodb-sdk/src/lib/formBuilder/index.ts
index 88c957a2a9..0452bdbc2e 100644
--- a/packages/nocodb-sdk/src/lib/formBuilder/index.ts
+++ b/packages/nocodb-sdk/src/lib/formBuilder/index.ts
@@ -65,6 +65,10 @@ export interface FormBuilderSelectOption {
ncItemDisabled?: boolean;
/** Reason for the disabled state **/
ncItemTooltip?: string;
+ /**
+ * Icon for the option (IconMapKey)
+ */
+ icon?: string;
}
/**
@@ -131,6 +135,11 @@ interface FormBuilderElementBase {
border?: boolean;
/** Show hint as tooltip instead of inline text */
showHintAsTooltip?: boolean;
+ /**
+ * Just to show required asterisk in label
+ * @note: Use required field validator along with this to ensure field is required
+ * */
+ required?: boolean;
/** Validators for field validation */
validators?: FormBuilderValidator[];
/** Model path(s) this field depends on - when dependency changes, options are reloaded */