|
20 | 20 | ref="input" |
21 | 21 | :key="`select-${column.name}-${source}-${column.foreignResource?.name || column.foreignResource?.table || ''}`" |
22 | 22 | class="w-full min-w-24" |
23 | | - :options="columnOptions[column.name] || []" |
| 23 | + :options="formatSelectOptions(columnOptions[column.name] || [], column)" |
24 | 24 | :searchDisabled="!column.foreignResource.searchableFields" |
25 | 25 | @scroll-near-end="loadMoreOptions && loadMoreOptions(column.name)" |
26 | 26 | @search="(searchTerm) => { |
|
33 | 33 | :modelValue="value" |
34 | 34 | :readonly="(column.editReadonly && source === 'edit') || readonly" |
35 | 35 | @update:modelValue="$emit('update:modelValue', $event)" |
| 36 | + disableTogleOfSelectedItem |
36 | 37 | > |
37 | 38 | <template #extra-item v-if="columnLoadingState && columnLoadingState[column.name]?.loading"> |
38 | 39 | <div class="text-center text-gray-400 dark:text-gray-300 py-2 flex items-center justify-center gap-2"> |
|
45 | 46 | v-else-if="column.enum" |
46 | 47 | ref="input" |
47 | 48 | class="w-full min-w-24" |
48 | | - :options="column.enum" |
| 49 | + :options="formatSelectOptions(column.enum, column)" |
49 | 50 | teleportToBody |
50 | 51 | :modelValue="value" |
51 | 52 | :readonly="(column.editReadonly && source === 'edit') || readonly" |
52 | 53 | @update:modelValue="$emit('update:modelValue', $event)" |
| 54 | + disableTogleOfSelectedItem |
53 | 55 | /> |
54 | 56 | <Select |
55 | 57 | v-else-if="(type || column.type) === 'boolean'" |
|
60 | 62 | :modelValue="value" |
61 | 63 | :readonly="(column.editReadonly && source === 'edit') || readonly" |
62 | 64 | @update:modelValue="$emit('update:modelValue', $event)" |
| 65 | + disableTogleOfSelectedItem |
63 | 66 | /> |
64 | 67 | <Input |
65 | 68 | v-else-if="['integer'].includes(type || column.type)" |
|
188 | 191 | type?: string, |
189 | 192 | value: any, |
190 | 193 | currentValues: any, |
191 | | - mode: string, |
| 194 | + mode: 'create' | 'edit', |
192 | 195 | columnOptions: any, |
193 | 196 | unmasked: any, |
194 | 197 | deletable?: boolean, |
@@ -218,6 +221,16 @@ const input = ref<HTMLInputElement | null>(null); |
218 | 221 | return options; |
219 | 222 | }; |
220 | 223 |
|
| 224 | + const formatSelectOptions = (options: any, column: any) => { |
| 225 | + const optionsToReturn = options; |
| 226 | + if (!column.required[props.mode] && !column.isArray?.enabled) { |
| 227 | + if (!optionsToReturn.some((option: any) => option.value === null)) { |
| 228 | + optionsToReturn.push({ label: t('Unset'), value: null }); |
| 229 | + } |
| 230 | + } |
| 231 | + return optionsToReturn; |
| 232 | + }; |
| 233 | +
|
221 | 234 | function onFocusHandler(event:FocusEvent, column:any, source:string, ) { |
222 | 235 | const focusedInput = event.target as HTMLInputElement; |
223 | 236 | if(!focusedInput) return; |
|
0 commit comments