Skip to content

Commit

Permalink
Merge pull request #55 from suvarnakale/release-1.0.0
Browse files Browse the repository at this point in the history
Issue #0000 chore: multiselect and maxselection for one condition added
  • Loading branch information
itsvick authored Jul 29, 2024
2 parents 20fc91a + 508cbd1 commit 3e96857
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/components/GeneratedSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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') {
Expand Down

0 comments on commit 3e96857

Please sign in to comment.