init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
77
KretaWeb/Helpers/TextBoxPasswordExtensions.cs
Normal file
77
KretaWeb/Helpers/TextBoxPasswordExtensions.cs
Normal file
|
@ -0,0 +1,77 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Mvc.Html;
|
||||
using Kendo.Mvc.UI;
|
||||
using Kendo.Mvc.UI.Fluent;
|
||||
|
||||
namespace Kreta.Web.Helpers
|
||||
{
|
||||
public static class TextBoxPasswordExtensions
|
||||
{
|
||||
public static TextBoxBuilder<string> KretaPassword(this HtmlHelper helper, string name, bool enabled = true, Dictionary<string, object> htmlAttributes = null)
|
||||
{
|
||||
var tb = helper.Kendo().TextBox()
|
||||
//.Name(Guid.NewGuid().ToString())
|
||||
.Name(name)
|
||||
.Enable(enabled);
|
||||
|
||||
if (htmlAttributes == null)
|
||||
{
|
||||
htmlAttributes = new Dictionary<string, object>();
|
||||
}
|
||||
|
||||
htmlAttributes.Add("type", "password");
|
||||
htmlAttributes.Add("name", name);
|
||||
|
||||
tb.HtmlAttributes(htmlAttributes);
|
||||
|
||||
return tb;
|
||||
}
|
||||
|
||||
public static TextBoxBuilder<string> KretaPasswordFor<TModel, TValue>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TValue>> expression, Dictionary<string, object> htmlAttributes = null)
|
||||
{
|
||||
var fieldName = ExpressionHelper.GetExpressionText(expression);
|
||||
var fullBindingName = helper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(fieldName);
|
||||
var metadata = ModelMetadata.FromLambdaExpression(expression, helper.ViewData);
|
||||
var value = metadata.Model;
|
||||
|
||||
if (htmlAttributes == null)
|
||||
htmlAttributes = new Dictionary<string, object>();
|
||||
|
||||
var attributes = Mapper.GetUnobtrusiveValidationAttributes(helper, expression, htmlAttributes, metadata);
|
||||
foreach (var key in attributes.Keys)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!key.Contains("equalto") && htmlAttributes.ContainsKey(key) == false)
|
||||
{
|
||||
htmlAttributes.Add(key, attributes[key].ToString());
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
var validationAttributes = helper.GetUnobtrusiveValidationAttributes(fullBindingName, metadata);
|
||||
|
||||
if (metadata.IsRequired)
|
||||
{ htmlAttributes.Add("data-labelmsg", metadata.DisplayName + " *"); }
|
||||
else
|
||||
{ htmlAttributes.Add("data-labelmsg", metadata.DisplayName); }
|
||||
|
||||
htmlAttributes.Add("type", "password");
|
||||
|
||||
var tb = helper.Kendo().TextBox()
|
||||
.Name(fullBindingName)
|
||||
.HtmlAttributes(htmlAttributes);
|
||||
|
||||
if (value != null)
|
||||
tb.Value(value.ToString());
|
||||
|
||||
return tb;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue