Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added data attribute to most of the form field elements

  • Loading branch information...
commit a7ec62612f8548e2ea89c5adc7de44e5b3dbaa22 1 parent c23ca7c
Shashank Shetty shashankshetty authored
1  src/FluentWebControls/CheckBoxData.cs
View
@@ -120,6 +120,7 @@ public override string ToString()
{
sb.Append(CssClass.CreateQuotedAttribute("class"));
}
+ sb.Append(Data);
sb.Append("/>");
AppendLabel(sb);
return sb.ToString();
1  src/FluentWebControls/ComboSelectData.cs
View
@@ -40,6 +40,7 @@ public override string ToString()
sb.AppendFormat(BuildJqueryValidation(CssClass.Join(" ")).CreateQuotedAttribute("class"));
sb.Append("multiple".CreateQuotedAttribute("multiple"));
sb.Append(Size.CreateQuotedAttribute("size"));
+ sb.Append(Data);
if (!TabIndex.IsNullOrEmpty())
{
sb.Append(TabIndex.CreateQuotedAttribute("tabindex"));
1  src/FluentWebControls/DropDownListData.cs
View
@@ -158,6 +158,7 @@ public override string ToString()
sb.Append(NameWithPrefix.CreateQuotedAttribute("name"));
sb.Append(idWithPrefix.CreateQuotedAttribute("id"));
sb.AppendFormat(BuildJqueryValidation(CssClass).CreateQuotedAttribute("class"));
+ sb.Append(Data);
if (SubmitOnChange)
{
string v = _formFieldToSetBeforeSubmitting != null
15 src/FluentWebControls/Extensions/IWebControlExtensions.cs
View
@@ -1,6 +1,6 @@
using System;
using System.Linq.Expressions;
-
+using Microsoft.Build.Framework.XamlTypes;
using MvbaCore;
namespace FluentWebControls.Extensions
@@ -13,12 +13,23 @@ public static class IWebControlExtensions
return webControl;
}
+ public static T WithData<T>(this T webControl, string name, string value) where T : IWebControl
+ {
+ webControl.Data = new NameValuePair
+ {
+ Name = name,
+ Value = value
+ };
+ return webControl;
+ }
+
public static T WithId<T, TFuncResult>(this T webControl, Expression<Func<TFuncResult>> id) where T : IWebControl
{
return webControl.WithId(Reflection.GetPropertyName(id));
}
- public static T WithId<T, TFuncInput, TFuncResult>(this T webControl, Expression<Func<TFuncInput, TFuncResult>> id) where T : IWebControl
+ public static T WithId<T, TFuncInput, TFuncResult>(this T webControl, Expression<Func<TFuncInput, TFuncResult>> id)
+ where T : IWebControl
{
return webControl.WithId(Reflection.GetPropertyName(id));
}
1  src/FluentWebControls/FluentWebControls.csproj
View
@@ -55,6 +55,7 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\JetBrains.Annotations\JetBrains.Annotations.dll</HintPath>
</Reference>
+ <Reference Include="Microsoft.Build.Framework" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="MvbaCore, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
3  src/FluentWebControls/IWebControl.cs
View
@@ -1,3 +1,5 @@
+using Microsoft.Build.Framework.XamlTypes;
+
namespace FluentWebControls
{
public interface IWebControl
@@ -5,5 +7,6 @@ public interface IWebControl
string Id { get; set; }
string IdPrefix { get; set; }
string NamePrefix { get; set; }
+ NameValuePair Data { get; set; }
}
}
1  src/FluentWebControls/RadioButtonData.cs
View
@@ -96,6 +96,7 @@ public override string ToString()
sb.Append(IdWithPrefix.CreateQuotedAttribute("id"));
sb.Append(NameWithPrefix.CreateQuotedAttribute("name"));
}
+ sb.Append(Data);
if (Checked)
{
sb.Append("checked".CreateQuotedAttribute("checked"));
2  src/FluentWebControls/TextAreaData.cs
View
@@ -92,7 +92,7 @@ public override string ToString()
sb.Append(value.CreateQuotedAttribute("style"));
}
sb.Append(BuildJqueryValidation(CssClass).CreateQuotedAttribute("class"));
-
+ sb.Append(Data);
if (PropertyMetaData != null)
{
if (PropertyMetaData.MinLength > 0)
2  src/FluentWebControls/TextBoxData.cs
View
@@ -133,7 +133,7 @@ public override string ToString()
sb.Append(value.CreateQuotedAttribute("style"));
}
sb.Append(BuildJqueryValidation(CssClass).CreateQuotedAttribute("class"));
-
+ sb.Append(Data);
if (PropertyMetaData != null)
{
if (PropertyMetaData.MinLength > 0)
26 src/FluentWebControls/WebControlBase.cs
View
@@ -1,4 +1,6 @@
using System;
+using FluentWebControls.Extensions;
+using Microsoft.Build.Framework.XamlTypes;
namespace FluentWebControls
{
@@ -8,12 +10,12 @@ protected string IdWithPrefix
{
get
{
- string prefix = ((IWebControl)this).IdPrefix ?? "";
- if (!String.IsNullOrEmpty(((IWebControl)this).IdPrefix))
+ string prefix = ((IWebControl) this).IdPrefix ?? "";
+ if (!String.IsNullOrEmpty(((IWebControl) this).IdPrefix))
{
prefix += Constants.WebCompatibleSeparator;
}
- var id = ((IWebControl)this).Id;
+ string id = ((IWebControl) this).Id;
if (prefix.IsNullOrEmpty())
{
id = id.ToCamelCase();
@@ -22,16 +24,17 @@ protected string IdWithPrefix
return id;
}
}
+
protected string NameWithPrefix
{
get
{
- string prefix = ((IWebControl)this).NamePrefix ?? "";
- if (!String.IsNullOrEmpty(((IWebControl)this).NamePrefix))
+ string prefix = ((IWebControl) this).NamePrefix ?? "";
+ if (!String.IsNullOrEmpty(((IWebControl) this).NamePrefix))
{
prefix += ".";
}
- var id = ((IWebControl)this).Id;
+ string id = ((IWebControl) this).Id;
if (prefix.IsNullOrEmpty())
{
id = id.ToCamelCase();
@@ -40,8 +43,19 @@ protected string NameWithPrefix
return id;
}
}
+
+ protected string Data
+ {
+ get
+ {
+ var data = ((IWebControl) this).Data;
+ return data != null && !data.Name.IsNullOrEmpty() ? data.Value.CreateQuotedAttribute(String.Format("data-{0}", data.Name)) : "";
+ }
+ }
+
string IWebControl.Id { get; set; }
string IWebControl.IdPrefix { get; set; }
string IWebControl.NamePrefix { get; set; }
+ NameValuePair IWebControl.Data { get; set; }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.