Sep 29, 2014 at 2:48 PM
Edited Sep 29, 2014 at 2:56 PM
I noticed a strange problem with EnumerationField, when I try to change the selected values via code. I use the property SelectedValues to set the selected values, like this:
enumerationField.SelectedValues = arrayOfValues;
But when I do that for a normal ComboBox (so not multiselect), Orchard does now show the selected value in the editor view.
After some debugging I noticed that the Field.Value (which is used in the editor view) contains ";MySelectedValue;". Of course there exists no value like that, so it does not select the proper value in the selectbox. When I take a look in the code
I see that it does this:
Value = Separator + string.Join(Separator.ToString(), value) + Separator;
So that seems to be the problem to me. Why does it even do this, what's the point? String.Join should always add the proper amount of seperators, so there's no need to add extra ones?
Should I file a bug for this, or is this intended behavior? If the latter, how should I set my selected values then?
I have a workaround for now, which is to use this:
enumerationField.Value = String.Join(";", arrayOfValues);
I could also check what the ListMode of the EnumerationField is and then use Value for ComboBox or SelectedValues for ListBox, but that seems like exaggerated code to me... It should work no matter what ListMode I use, IMO.