Permalink
Browse files

Added some bootstrap EditorTemplates

  • Loading branch information...
1 parent 9ba61a6 commit 0be4325fed69420dab04c2f4f34fc9fc88b976cb @gazk committed Mar 13, 2012
@@ -212,6 +212,10 @@
<None Include="CodeTemplates\AddView\CSHTML\Edit.tt" />
<None Include="CodeTemplates\AddView\CSHTML\Empty.tt" />
<None Include="CodeTemplates\AddView\CSHTML\List.tt" />
+ <Content Include="Views\Shared\EditorTemplates\Boolean.cshtml" />
+ <Content Include="Views\Shared\EditorTemplates\DateTime.cshtml" />
+ <Content Include="Views\Shared\EditorTemplates\Decimal.cshtml" />
+ <Content Include="Views\Shared\EditorTemplates\String.cshtml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
@@ -0,0 +1,13 @@
+@model bool?
+@{
+ var helperText = string.Empty;
+ if (ViewData.ModelMetadata.AdditionalValues.ContainsKey("helpertext"))
+ {
+ helperText = ViewData.ModelMetadata.AdditionalValues["helpertext"] as string;
+ }
+}
+
+<label class="checkbox">
+ @Html.CheckBox("", Model.GetValueOrDefault())
+ @helperText
+</label>
@@ -0,0 +1,8 @@
+@model DateTime?
+
+@{
+ var htmlAttributes = new Dictionary<string, object> {{"data-datepicker", "datepicker"},
+ {"class", "input-small"}};
+
+}
+@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, htmlAttributes)
@@ -0,0 +1,3 @@
+@model Decimal?
+
+@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, new { @class = "input-medium" })
@@ -0,0 +1,53 @@
+@model String
+@{
+ // Bootstrap text box sizes - using the StringLengthAttributeAdapter to set the box size and maxlength attribute
+ var cssClass = "input-xlarge"; // Default
+
+ var htmlAttributes = new Dictionary<string, object>();
+
+ foreach (var v in ViewData.ModelMetadata.GetValidators(ViewContext.Controller.ControllerContext))
+ {
+ var attr = v as StringLengthAttributeAdapter;
+ if (attr != null)
+ {
+ var validationParameters = attr.GetClientValidationRules().First().ValidationParameters;
+
+ if (validationParameters.ContainsKey("max"))
+ {
+ var maxLength = (int) validationParameters["max"];
+
+ htmlAttributes.Add("maxlength", maxLength);
+
+ if (maxLength <= 8)
+ {
+ cssClass = "input-mini";
+ }
+ else if (maxLength <= 12)
+ {
+ cssClass = "input-small";
+ }
+ else if (maxLength <= 20)
+ {
+ cssClass = "input-medium";
+ }
+ else if (maxLength <= 30)
+ {
+ cssClass = "input-large";
+ }
+ else if (maxLength <= 50)
+ {
+ cssClass = "input-xlarge";
+ }
+ else
+ {
+ cssClass = "input-xxlarge";
+ }
+ }
+ }
+ }
+
+ htmlAttributes.Add("class", cssClass);
+}
+
+@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, htmlAttributes)
+

0 comments on commit 0be4325

Please sign in to comment.