Fixed binding issue for Enumeration field when using RadioList.

This fixes an issue when the Enumeration content field is configured to use radio buttons - in which case the editor shape will use the "Value" property instead of the "SelectedValues" property. Since the binding would only set the value through "SelectedValues", the stored value would be surrounded with a comma, which would not match with any of the enumeration values.
This commit is contained in:
Sipke Schoorstra
2015-05-01 16:39:50 +02:00
parent cd479efdae
commit 379ac040e1

View File

@@ -8,8 +8,19 @@ namespace Orchard.DynamicForms.Bindings {
public void Describe(BindingDescribeContext context) {
context.For<EnumerationField>()
.Binding("SelectedValues", (contentItem, field, s) => {
var items = (s ?? "").Split(new[] {',', ';'}, StringSplitOptions.RemoveEmptyEntries);
field.SelectedValues = items;
if (String.IsNullOrWhiteSpace(s)) {
field.Value = "";
return;
}
var separators = new[] {',', ';'};
var hasMultipleValues = s.IndexOfAny(separators) >= 0;
if (hasMultipleValues)
field.SelectedValues = s.Split(separators, StringSplitOptions.RemoveEmptyEntries);
else {
field.Value = s;
}
});
}
}