Files
Orchard/src/Orchard.Web/Modules/Orchard.DynamicForms/Drivers/RadioButtonElementDriver.cs
2015-04-04 17:22:17 +02:00

46 lines
1.7 KiB
C#

using System.Collections.Generic;
using Orchard.DynamicForms.Elements;
using Orchard.Forms.Services;
using Orchard.Layouts.Framework.Display;
using Orchard.Layouts.Framework.Drivers;
using Orchard.Tokens;
using DescribeContext = Orchard.Forms.Services.DescribeContext;
namespace Orchard.DynamicForms.Drivers {
public class RadioButtonElementDriver : FormsElementDriver<RadioButton> {
private readonly ITokenizer _tokenizer;
public RadioButtonElementDriver(IFormManager formManager, ITokenizer tokenizer)
: base(formManager) {
_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.TokenizedValue = _tokenizer.Replace(element.Value, null);
}
}
}