Skip to content

Commit b3412fd

Browse files
authored
Merge pull request #9482 from GilbertCherrie/fix_copy_request_dialog_form
Fixed the copy request dialog form
2 parents bd55b4d + c05a2c3 commit b3412fd

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

app/controllers/miq_request_controller.rb

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def prov_copy
218218
)
219219

220220
if req.kind_of?(ServiceTemplateProvisionRequest)
221-
@dialog_replace_data = req.options[:dialog].map { |key, val| {:name => key.split('dialog_').last, :value => val } }.to_json
221+
@dialog_replace_data = req.options[:dialog].map { |key, val| {:name => key.split('dialog_').last, :value => parse_val(key, val)} }.to_json
222222
@new_dialog = true
223223
template = find_record_with_rbac(ServiceTemplate, req.source_id)
224224
resource_action = template.resource_actions.find { |r| r.action.downcase == 'provision' && r.dialog_id }
@@ -338,6 +338,35 @@ def menu_section_id(parms = {})
338338

339339
private
340340

341+
def parse_val(key, val)
342+
if val.kind_of?(Integer) # Handle integer values
343+
if key.include?("Array::") # Handle multi select with integers
344+
val = [val]
345+
else # Handle single select with integers
346+
return val
347+
end
348+
end
349+
350+
# TODO: Tag Control Field currently does not handle default values
351+
if val.include?("Classification::") # Handle tag control default values
352+
if val.include?("\u001F") # Array of tags
353+
val = val.split("\u001F").map do |tag|
354+
Classification.find_by(:id => tag.split('::').second).id
355+
end
356+
else # Single tag
357+
val = Classification.find_by(:id => val.split('::').second).id
358+
end
359+
elsif key.include?("Array::") # Handle drop down with multi select default values
360+
if val.kind_of?(String) && val.include?("\u001F") # Check if string is an array of values
361+
val = val.split("\u001F") # Split the string into an array
362+
else
363+
val = [val] # Handle single string value
364+
end
365+
end
366+
367+
val # Handles all other conditions such as non-multi-select drop downs, text fields, etc.
368+
end
369+
341370
def replace_gtl
342371
render :update do |page|
343372
page << javascript_prologue

app/javascript/oldjs/controllers/dialog_user/dialog_user_controller.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ ManageIQ.angular.app.controller('dialogUserController', ['API', 'dialogFieldRefr
2222
_.forEach(tab.dialog_groups, function(group) {
2323
_.forEach(group.dialog_fields, function(field) {
2424
const replaceField = dialogReplaceData ? JSON.parse(dialogReplaceData).find(function (replace) { return replace.name === field.name }) : false;
25+
26+
// Handles multi-select dropdowns with integer values
27+
if (field.type === 'DialogFieldDropDownList' && field.data_type === 'integer' && replaceField.value && Array.isArray(replaceField.value)) {
28+
replaceField.value = replaceField.value.map(function (value) {
29+
return parseInt(value, 10);
30+
});
31+
}
32+
2533
if (replaceField) {
2634
field.default_value = replaceField.value;
2735
}

0 commit comments

Comments
 (0)