Skip to content

Commit

Permalink
refactoring multiselect drop down field
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffibm committed Nov 16, 2023
1 parent e23acbf commit 981b45c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
18 changes: 14 additions & 4 deletions app/javascript/components/service-dialog/viewFields.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,27 @@ export const buildRefreshButton = (field, tabIndex) => ({
},
});

const convertStringToArray = (inputString) => {
const regex = /\\x([0-9A-Fa-f]+)/g;
const replacedString = inputString.replace(regex, (match, capture) => String.fromCharCode(parseInt(capture, 16)));
return replacedString.split('\x1F');
};

const buildOptions = (field, initialValues) => {
const placeholder = __('<Choose>');

let options = [
{ label: 'Options1', value: 1 },
{ label: 'Options2', value: 2 },
];
const fieldName = appendKeyName(field.name);
const selectedOptions = initialValues && initialValues[fieldName];
const selectedOptions = (initialValues && field.options.force_multi_value)
? initialValues[`Array::${fieldName}`]
: initialValues[fieldName];
if (selectedOptions) {
options = [{ label: selectedOptions.toString(), value: selectedOptions }];
options = convertStringToArray(selectedOptions)
.map((item) => ({ label: item.toString(), value: item }));
}
const placeholder = __('<Choose>');
return { options, placeholder, fieldName };
};

Expand All @@ -182,7 +192,7 @@ export const buildDropDownList = (field, initialValues) => {
labelText: field.label,
hideField: !field.visible,
isRequired: field.required,
isDisabled: true,
isDisabled: false,
initialValue: field.default_value,
description: field.description,
options,
Expand Down
1 change: 1 addition & 0 deletions app/views/miq_request/_st_prov_show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
= _("Dialog Options")
.row
.col-md-12.col-lg-12
= @miq_request.id
- request_options = @miq_request.options
= react('ServiceDialog', {:recordId => request_options[:workflow_settings][:dialog_id],
:initialValues => request_options[:dialog]})
Expand Down

0 comments on commit 981b45c

Please sign in to comment.