Permalink
Browse files

can have different name and id for a form field

  • Loading branch information...
1 parent ba6ad00 commit 227330918a551e6de4958e3ada0e47b0ab6592ff @shashankshetty shashankshetty committed Mar 27, 2013
@@ -7,7 +7,8 @@ public static class IBooleanMapExtensions
public static CheckBoxData AsCheckBox(this IBooleanMap input)
{
return new CheckBoxData(input.IsChecked)
- .WithId(input.Id);
+ .WithId(input.Id)
+ .WithName(input.Id);
}
}
}
@@ -8,6 +8,7 @@ public static ComboSelectData AsComboSelect(this IChoiceListMap input)
{
var comboSelect = new ComboSelectData(input.ListItems)
.WithId(input.Id)
+ .WithName(input.Id)
.WithValidationFrom(input.Validation);
comboSelect.SelectedValues.AddRange(input.SelectedValues);
return comboSelect;
@@ -17,6 +18,7 @@ public static CheckBoxListData AsCheckBoxList(this IChoiceListMap input)
{
var checkBoxList = new CheckBoxListData(input.ListItems)
.WithId(input.Id)
+ .WithName(input.Id)
.WithValidationFrom(input.Validation);
checkBoxList.SelectedValues.AddRange(input.SelectedValues);
return checkBoxList;
@@ -26,6 +28,7 @@ public static RadioButtonListData AsRadioButtons(this IChoiceListMap input)
{
var radioButtons = new RadioButtonListData(input.ListItems)
.WithId(input.Id)
+ .WithName(input.Id)
.WithValidationFrom(input.Validation);
radioButtons.SelectedValue = input.SelectedValue;
return radioButtons;
@@ -36,6 +39,7 @@ public static DropDownListData AsDropDownList(this IChoiceListMap input)
return new DropDownListData(input.ListItems)
.WithSelectedValue(input.SelectedValue)
.WithId(input.Id)
+ .WithName(input.Id)
.WithValidationFrom(input.Validation);
}
}
@@ -8,26 +8,30 @@ public static HiddenData AsHidden(this IFreeTextMap input)
{
return new HiddenData()
.WithValue(input.Value)
- .WithId(input.Id);
+ .WithId(input.Id)
+ .WithName(input.Id);
}
public static SpanData AsSpan(this IFreeTextMap input)
{
return new SpanData(input.Value)
- .WithId(input.Id);
+ .WithId(input.Id)
+ .WithName(input.Id);
}
public static TextAreaData AsTextArea(this IFreeTextMap input)
{
return new TextAreaData(input.Value)
.WithId(input.Id)
+ .WithName(input.Id)
.WithValidationFrom(input.Validation);
}
public static TextBoxData AsTextBox(this IFreeTextMap input)
{
return new TextBoxData(input.Value)
.WithId(input.Id)
+ .WithName(input.Id)
.WithValidationFrom(input.Validation);
}
}
@@ -13,6 +13,12 @@ public static class IWebControlExtensions
return webControl;
}
+ public static T WithName<T>(this T webControl, string name) where T : IWebControl
+ {
+ webControl.Name = name;
+ return webControl;
+ }
+
public static T WithData<T>(this T webControl, string name, string value) where T : IWebControl
{
webControl.Data = new NameValuePair
@@ -34,6 +40,12 @@ public static class IWebControlExtensions
return webControl.WithId(Reflection.GetPropertyName(id));
}
+ public static T WithName<T, TFuncInput, TFuncResult>(this T webControl, Expression<Func<TFuncInput, TFuncResult>> name)
+ where T : IWebControl
+ {
+ return webControl.WithName(Reflection.GetPropertyName(name));
+ }
+
public static T WithIdPrefix<T>(this T webControl, string idPrefix) where T : IWebControl
{
webControl.IdPrefix = idPrefix.ToCamelCase();
@@ -6,6 +6,7 @@ public interface IWebControl
{
string Id { get; set; }
string IdPrefix { get; set; }
+ string Name { get; set; }
string NamePrefix { get; set; }
NameValuePair Data { get; set; }
}
@@ -29,18 +29,25 @@ protected string NameWithPrefix
{
get
{
- string prefix = ((IWebControl) this).NamePrefix ?? ((IWebControl) this).IdPrefix ?? "";
+ var name = ((IWebControl)this).Name;
+ var id = ((IWebControl)this).Id;
+ string prefix = ((IWebControl) this).NamePrefix ?? "";
+
+ if (name == id && prefix.IsNullOrEmpty())
+ {
+ prefix = ((IWebControl)this).IdPrefix ?? "";
+ }
if (!String.IsNullOrEmpty(prefix))
{
prefix += ".";
}
- string id = ((IWebControl) this).Id;
+ name = name ?? id;
if (prefix.IsNullOrEmpty())
{
- id = id.ToCamelCase();
+ name = name.ToCamelCase();
}
- id = prefix + id;
- return id;
+ name = prefix + name;
+ return name;
}
}
@@ -49,11 +56,14 @@ protected string Data
get
{
var data = ((IWebControl) this).Data;
- return data != null && !data.Name.IsNullOrEmpty() ? data.Value.CreateQuotedAttribute(String.Format("data-{0}", data.Name)) : "";
+ return data != null && !data.Name.IsNullOrEmpty()
+ ? data.Value.CreateQuotedAttribute(String.Format("data-{0}", data.Name))
+ : "";
}
}
string IWebControl.Id { get; set; }
+ string IWebControl.Name { get; set; }
string IWebControl.IdPrefix { get; set; }
string IWebControl.NamePrefix { get; set; }
NameValuePair IWebControl.Data { get; set; }

0 comments on commit 2273309

Please sign in to comment.