Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/aspnetwebstack.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel de Icaza <miguel@gnome.org>2012-03-28 04:03:56 +0400
committerbradwilson <dotnetguy@gmail.com>2012-03-28 04:12:52 +0400
commit68a34436db0c25068b2d437f72ca59ac67239b27 (patch)
tree28985b19abeff3cf638fd90c3cf48372df52c08d /src/System.Web.Mvc
parent5c4393363d8c4e39a3f9d4fed6c71da3d9873321 (diff)
Add HTML5 input type support for telphone, url, dates, times, numbers and email.
This fixes workitem #2: http://aspnetwebstack.codeplex.com/workitem/2 * src/System.Web.Mvc/Html/DefaultEditorTemplates.cs (CreateHtmlAttributes): Parametrize input to take an optional inputType string. (PhoneNumberInputTemplate, UrlInputTemplate, HtmlInputTemplateHelper, HtmlInputTemplateHelper, DateTimeInputTemplate, DateInputTemplate, TimeInputTemplate, NumberInputTemplate, HtmlInputTemplateHelper): New HTLP5 helper methods. * src/System.Web.Mvc/Html/TemplateHelpers.cs: (_defaultEditorActions): register the new actions. * test/System.Web.Mvc.Test/Html/Test/DefaultEditorTemplatesTest.cs: Add unit tests for the new template helper methods.
Diffstat (limited to 'src/System.Web.Mvc')
-rw-r--r--src/System.Web.Mvc/Html/DefaultEditorTemplates.cs57
-rw-r--r--src/System.Web.Mvc/Html/TemplateHelpers.cs12
2 files changed, 64 insertions, 5 deletions
diff --git a/src/System.Web.Mvc/Html/DefaultEditorTemplates.cs b/src/System.Web.Mvc/Html/DefaultEditorTemplates.cs
index c19b9986..5130e3e7 100644
--- a/src/System.Web.Mvc/Html/DefaultEditorTemplates.cs
+++ b/src/System.Web.Mvc/Html/DefaultEditorTemplates.cs
@@ -148,12 +148,17 @@ namespace System.Web.Mvc.Html
CreateHtmlAttributes("text-box multi-line")).ToHtmlString();
}
- private static IDictionary<string, object> CreateHtmlAttributes(string className)
+ private static IDictionary<string, object> CreateHtmlAttributes(string className, string inputType = null)
{
- return new Dictionary<string, object>()
+ var htmlAttributes = new Dictionary<string, object>()
{
{ "class", className }
};
+ if (inputType != null)
+ {
+ htmlAttributes.Add("type", inputType);
+ }
+ return htmlAttributes;
}
internal static string ObjectTemplate(HtmlHelper html)
@@ -218,9 +223,51 @@ namespace System.Web.Mvc.Html
internal static string StringTemplate(HtmlHelper html)
{
- return html.TextBox(String.Empty,
- html.ViewContext.ViewData.TemplateInfo.FormattedModelValue,
- CreateHtmlAttributes("text-box single-line")).ToHtmlString();
+ return HtmlInputTemplateHelper(html);
+ }
+
+ internal static string PhoneNumberInputTemplate(HtmlHelper html)
+ {
+ return HtmlInputTemplateHelper(html, inputType: "tel");
+ }
+
+ internal static string UrlInputTemplate(HtmlHelper html)
+ {
+ return HtmlInputTemplateHelper(html, inputType: "url");
+ }
+
+ internal static string EmailAddressInputTemplate(HtmlHelper html)
+ {
+ return HtmlInputTemplateHelper(html, inputType: "email");
+ }
+
+ internal static string DateTimeInputTemplate(HtmlHelper html)
+ {
+ return HtmlInputTemplateHelper(html, inputType: "datetime");
+ }
+
+ internal static string DateInputTemplate(HtmlHelper html)
+ {
+ return HtmlInputTemplateHelper(html, inputType: "date");
+ }
+
+ internal static string TimeInputTemplate(HtmlHelper html)
+ {
+ return HtmlInputTemplateHelper(html, inputType: "time");
+ }
+
+ internal static string NumberInputTemplate(HtmlHelper html)
+ {
+ return HtmlInputTemplateHelper(html, inputType: "number");
+ }
+
+ private static string HtmlInputTemplateHelper(HtmlHelper html, string inputType = null)
+ {
+ return html.TextBox(
+ name: String.Empty,
+ value: html.ViewContext.ViewData.TemplateInfo.FormattedModelValue,
+ htmlAttributes: CreateHtmlAttributes(className: "text-box single-line", inputType: inputType))
+ .ToHtmlString();
}
internal static List<SelectListItem> TriStateValues(bool? value)
diff --git a/src/System.Web.Mvc/Html/TemplateHelpers.cs b/src/System.Web.Mvc/Html/TemplateHelpers.cs
index 26290b8c..41f149cc 100644
--- a/src/System.Web.Mvc/Html/TemplateHelpers.cs
+++ b/src/System.Web.Mvc/Html/TemplateHelpers.cs
@@ -42,6 +42,18 @@ namespace System.Web.Mvc.Html
{ "Password", DefaultEditorTemplates.PasswordTemplate },
{ "Text", DefaultEditorTemplates.StringTemplate },
{ "Collection", DefaultEditorTemplates.CollectionTemplate },
+ { "PhoneNumber", DefaultEditorTemplates.PhoneNumberInputTemplate },
+ { "Url", DefaultEditorTemplates.UrlInputTemplate },
+ { "EmailAddress", DefaultEditorTemplates.EmailAddressInputTemplate },
+ { "DateTime", DefaultEditorTemplates.DateTimeInputTemplate },
+ { "Date", DefaultEditorTemplates.DateInputTemplate },
+ { "Time", DefaultEditorTemplates.TimeInputTemplate },
+ { typeof(byte).Name, DefaultEditorTemplates.NumberInputTemplate },
+ { typeof(sbyte).Name, DefaultEditorTemplates.NumberInputTemplate },
+ { typeof(int).Name, DefaultEditorTemplates.NumberInputTemplate },
+ { typeof(uint).Name, DefaultEditorTemplates.NumberInputTemplate },
+ { typeof(long).Name, DefaultEditorTemplates.NumberInputTemplate },
+ { typeof(ulong).Name, DefaultEditorTemplates.NumberInputTemplate },
{ typeof(bool).Name, DefaultEditorTemplates.BooleanTemplate },
{ typeof(decimal).Name, DefaultEditorTemplates.DecimalTemplate },
{ typeof(string).Name, DefaultEditorTemplates.StringTemplate },