mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
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:
@@ -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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user