@@ -46,7 +46,21 @@ SPDX-License-Identifier: AGPL-3.0-or-later
4646 </div >
4747
4848 <div class =" profile-fields-user-dialog__row-body" >
49+ <NcSelect
50+ v-if =" field.definition.type === 'select'"
51+ class =" profile-fields-user-dialog__input"
52+ :input-id =" `profile-fields-user-dialog-value-${field.definition.id}`"
53+ :model-value =" selectOptionFor(field.definition.id)"
54+ :aria-label =" field.definition.label"
55+ :clearable =" true"
56+ :searchable =" false"
57+ :options =" selectOptionsFor(field.definition)"
58+ label =" label"
59+ :placeholder =" placeholderForField(field.definition.type)"
60+ @update:model-value =" updateSelectValue(field.definition.id, $event)"
61+ />
4962 <NcInputField
63+ v-else
5064 class =" profile-fields-user-dialog__input"
5165 :id =" `profile-fields-user-dialog-value-${field.definition.id}`"
5266 v-model =" userDraftValues[field.definition.id]"
@@ -159,22 +173,38 @@ export default defineComponent({
159173 })
160174 }
161175
162- const descriptionForType = (type : FieldType ) => ({
176+ const descriptionForType = (type : FieldType ): string => ({
163177 text: ' Free text stored as a scalar value.' ,
164178 number: ' Only numeric values are accepted.' ,
165- }[type ])
179+ select: ' Choose one of the predefined options.' ,
180+ } as Record <FieldType , string >)[type ]
166181
167- const placeholderForField = (type : FieldType ) => ({
182+ const placeholderForField = (type : FieldType ): string => ({
168183 text: ' Free text stored as a scalar value.' ,
169184 number: ' Enter a number' ,
170- }[type ])
185+ select: ' Choose a value' ,
186+ } as Record <FieldType , string >)[type ]
171187
172188 const plainNumberPattern = / ^ -? \d + (\. \d + )? $ /
173189
174- const inputModeForField = (type : FieldType ) => ({
190+ const inputModeForField = (type : FieldType ): string => ({
175191 text: ' text' ,
176192 number: ' decimal' ,
177- }[type ])
193+ select: ' text' ,
194+ } as Record <FieldType , string >)[type ]
195+
196+ const selectOptionsFor = (definition : FieldDefinition ) =>
197+ (definition .options ?? []).map ((opt : string ) => ({ value: opt , label: opt }))
198+
199+ const selectOptionFor = (fieldId : number ) => {
200+ const value = userDraftValues [fieldId ]?.trim ()
201+ return value ? { value , label: value } : null
202+ }
203+
204+ const updateSelectValue = (fieldId : number , option : { value: string , label: string } | null ) => {
205+ userDraftValues [fieldId ] = option ?.value ?? ' '
206+ clearFieldError (fieldId )
207+ }
178208
179209 const rawDraftValueFor = (fieldId : number ) => userDraftValues [fieldId ]?.trim () ?? ' '
180210
@@ -189,6 +219,13 @@ export default defineComponent({
189219 return ` ${field .definition .label } must be a plain numeric value. `
190220 }
191221
222+ if (field .definition .type === ' select' ) {
223+ const options = field .definition .options ?? []
224+ if (! options .includes (rawValue )) {
225+ return ` ${field .definition .label } must be one of the allowed options. `
226+ }
227+ }
228+
192229 return null
193230 }
194231
@@ -268,7 +305,7 @@ export default defineComponent({
268305 ' text fields expect a scalar value' : ` ${field .definition .label } must be plain text. ` ,
269306 ' number fields expect a numeric value' : ` ${field .definition .label } must be a numeric value. ` ,
270307 ' current_visibility is not supported' : ' The selected visibility is not supported.' ,
271- }[message ] ?? ` ${field .definition .label }: ${ message } ` )
308+ }[message ] ?? ( message . includes ( ' is not a valid option ' ) ? ` ${field .definition .label }: invalid option selected. ` : ` ${ field . definition . label }: ${ message }` ) )
272309 }
273310
274311 const extractApiMessage = (error : unknown ) => {
@@ -323,6 +360,7 @@ export default defineComponent({
323360 }
324361 }
325362
363+
326364 const currentPayload = (field : AdminEditableField ) => {
327365 return {
328366 value: field .value ?.value ?.value ?? null ,
@@ -451,6 +489,9 @@ export default defineComponent({
451489 userValueErrors ,
452490 visibilityOptionFor ,
453491 visibilityOptions ,
492+ selectOptionsFor ,
493+ selectOptionFor ,
494+ updateSelectValue ,
454495 }
455496 },
456497})
0 commit comments