From 508cbd1833e9044b7fb95b39e03ae0989293f6f6 Mon Sep 17 00:00:00 2001 From: suvarnakale Date: Mon, 29 Jul 2024 18:14:28 +0530 Subject: [PATCH] Issue #0000 chore: multiselect and maxselection for one condition added --- src/components/GeneratedSchemas.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/components/GeneratedSchemas.ts b/src/components/GeneratedSchemas.ts index 3339c6c0..ce34cc2e 100644 --- a/src/components/GeneratedSchemas.ts +++ b/src/components/GeneratedSchemas.ts @@ -134,7 +134,7 @@ export const GenerateSchemaAndUiSchema = ( // fieldUiSchema['ui:widget'] = 'select'; // } - if (isMultiSelect && type === 'drop_down') { + if (isMultiSelect && type === 'drop_down' && maxSelections !== 1) { fieldSchema.type = 'array'; fieldSchema.items = { type: 'string', @@ -149,7 +149,24 @@ export const GenerateSchemaAndUiSchema = ( if (maxSelections) { fieldSchema.maxItems = maxSelections; } - fieldUiSchema['ui:widget'] = 'MultiSelectDropdown'; + if (maxSelections === 1) { + fieldUiSchema['ui:widget'] = 'select'; + } else { + fieldUiSchema['ui:widget'] = 'MultiSelectDropdown'; + } + } + + if (isMultiSelect && maxSelections === 1 && type === 'drop_down') { + fieldSchema.type = 'string'; + fieldSchema.isDropdown = true; + fieldSchema.oneOf = options.map((opt: FieldOption) => ({ + const: opt.value, + title: + t(`FORM.${opt.label}`) === `FORM.${opt.label}` + ? opt.label + : t(`FORM.${opt.label}`), + })); + fieldUiSchema['ui:widget'] = 'select'; } if (!isMultiSelect && type === 'drop_down') {