Making dynamic dropdowns required?


#1

Does anyone have a current dynamic dialog dropdown that is marked as required? I can not get mine to work at the moment. I feel like they were working in the past at some point, but not now.

Per the docs, this should work, but does not seem to be:

# required: true / false
dialog_field["required"] = "true"

#2

Try:

dialog_field["required"] = true

I think the value should be a boolean rather than string (my bad, it’s a typo in the automate book)

pemcg


#3

Thanks @pemcg.

Unfortunately that does not help. Apparently the value of "<None>" when you have a dynamic dialog with a Refresh button, but that does not load values on initialization (so not yet run) is sufficient as far as “Required” goes.


#4

This was a bit of a brain fart for me.

Since I wasn’t loading the values on initialization the instance for the dynamic dialog was never instantiated. It being instantiated is what is setting the required value, whether required=true was in the schema or the method.


#5

How did you instantiate the code of the dynamic dropdown on form load? I have a multiselect dropdown and until I select/deselect a value unfortunately I’m allowed to submit the form without selecting anything (although marked as required).


#6

Have you checked what the value is in the logs? Perhaps something is being assigned?


#7

Actually there is a possible value assigned (in an Array), although the dropdown writes “Nothing selected”.

I need to set the default list empty.

I made the dropdown non-required, and submitted it by making sure nothing is selected (selecting and de-selecting the same item). InspectMe writes I have the following value:

<AEMethod inspectme>   Attribute - dialog_mydropdown: []

Ok, so I tried to set it in the method:

dialog_field['default_value'] = []

But this is what I ended up when submitting (without touching the dropdown):

<AEMethod inspectme>   Attribute - dialog_mydropdown: ["[]"]

This is still not good enough :frowning:


#8

Hmmm, looks like The Book’s snippet below should cover your use case?

values_hash = {}
values_hash[’!’] = ‘-- select from list --’
user_group = $evm.root[‘user’].ldap_group

Everyone can provision to DEV and UAT

values_hash[‘dev’] = “Development”
values_hash[‘uat’] = “User Acceptance Test”
if user_group.downcase =~ /administrators/
#
# Administrators can also provision to PRE-PROD and PROD
#
values_hash[‘pre-prod’] = “Pre-Production”
values_hash[‘prod’] = “Production”
end

list_values = {
‘sort_by’ => :value,
‘data_type’ => :string,
‘required’ => true,
‘values’ => values_hash
}
list_values.each { |key, value| $evm.object[key] = value }


#9

Thanks, actually I missed this note on the same page:

If an element is marked as Required then using ‘!’ as the default return on the prompt value will satisfy the ‘required’ stipulation without the user necessarily selecting anything from the presented drop-down list. This may not be desirable. For Required elements a preferred option would be to use nil as the default return, for example:

values_hash[nil] = '-- select from list --'

This would then not satisfy the ‘required’ stipulation, and so force the user to select a presented ‘real’ value from the drop-down list.

So I added

values_hash[nil] = '-- select item(s) --'

This seems to cure the issue in the single select dropdown list case. However, if I turn on Multiselect for the dropdown, I can submit the dialog without selecting anything. Actually, -- select item(s) -- is pre-selected. In this case the System/Process instance is not called and I do not see anything in the logs - behaves like I pressed Cancel.

I tried to add

dialog_field['default_value'] = nil

but this prevents the dialog appearing.

I also tried

dialog_field['default_value'] = [nil]

In this case Nothing selected is shown on the dropdown, but I can still submit the form.

So I still do not have a good solution for a mandatory multiselect dropdown, just one step closer.


#10

I’m using that in automate methods:
dialog_field[“required”]=true
dialog_field[“visible”]=true

values={}
values[nil]=""
dialog_field[“values”]=values
dialog_field[“default_value”]=nil

It works as expected, if nothing is selected I can’t submit the form. I need to select at least one item. Only improvement I would like is the ability to autorize only a certain number of selected items.


#11

Thanks Lork,

but I can’t get this working :frowning:. Here is the full code I’m testing:

dialog_field = $evm.object
dialog_field["required"]=true
dialog_field["visible"]=true

values={}
values[nil] = ""
values["first"] = "first item"
values["second"] = "second item"
dialog_field["values"]=values
dialog_field["default_value"]=nil

If I use this code above, my dialog does not show up at all. If I comment out the default value, the values are available, and NaN is shown as default option (and Submit button is active).