Files
Orchard/src/Orchard.Web/Modules/Orchard.DynamicForms/Drivers/RadioButtonElementDriver.cs
Sipke Schoorstra 8693b68ac7 Fixed a binding issue with FormsElementDriver.
This fixes the issue where form elements whose drivers inherit from FormsElementDriver would not persist their changes.

Fixes #6100, #6035
2015-12-03 22:47:29 +01:00

49 lines
1.9 KiB
C#

using System.Collections.Generic;
using Orchard.DynamicForms.Elements;
using Orchard.Layouts.Framework.Display;
using Orchard.Layouts.Framework.Drivers;
using Orchard.Layouts.Helpers;
using Orchard.Layouts.Services;
using Orchard.Tokens;
using DescribeContext = Orchard.Forms.Services.DescribeContext;
namespace Orchard.DynamicForms.Drivers {
public class RadioButtonElementDriver : FormsElementDriver<RadioButton> {
private readonly ITokenizer _tokenizer;
public RadioButtonElementDriver(IFormsBasedElementServices formsServices, ITokenizer tokenizer)
: base(formsServices) {
_tokenizer = tokenizer;
}
protected override IEnumerable<string> FormNames {
get {
yield return "AutoLabel";
yield return "RadioButton";
}
}
protected override void DescribeForm(DescribeContext context) {
context.Form("RadioButton", factory => {
var shape = (dynamic)factory;
var form = shape.Fieldset(
Id: "RadioButton",
Description: T("The label for this radio button."),
_Value: shape.Textbox(
Id: "Value",
Name: "Value",
Title: "Value",
Classes: new[] { "text", "medium", "tokenized" },
Description: T("The value of this radio button.")));
return form;
});
}
protected override void OnDisplaying(RadioButton element, ElementDisplayingContext context) {
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, context.GetTokenData());
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, context.GetTokenData());
context.ElementShape.ProcessedValue = _tokenizer.Replace(element.Value, context.GetTokenData());
}
}
}