This commit is contained in:
skidoodle 2024-03-13 00:33:46 +01:00
commit e124a47765
19374 changed files with 9806149 additions and 0 deletions

View file

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Web.Mvc;
using Kendo.Mvc.UI;
namespace Kreta.Web.Helpers
{
public static class AutoCompleteExtensions
{
public static Kendo.Mvc.UI.Fluent.AutoCompleteBuilder KretaAutoCompleteFor<TModel, TProperty>(this HtmlHelper<TModel> helper, System.Linq.Expressions.Expression<Func<TModel, TProperty>> expression, string id = "", string className = "")
{
var inputName = ExpressionHelper.GetExpressionText(expression);
var name = helper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(inputName);
var val = ModelMetadata.FromLambdaExpression(expression, helper.ViewData).Model;
if (helper.ViewData.ModelState[name] != null && helper.ViewData.ModelState[name].Errors.Count > 0)
className = string.Format("{0} input-validation-error", className);
var autocomplete = helper.Kendo().AutoCompleteFor(expression)
.Filter(FilterType.Contains)
.HighlightFirst(true).DataTextField("Text");
if (!string.IsNullOrWhiteSpace(className) || !string.IsNullOrWhiteSpace(id))
{
var attributes = new Dictionary<string, object>();
if (!string.IsNullOrWhiteSpace(className))
attributes.Add("class", className.Trim());
if (!string.IsNullOrWhiteSpace(id))
attributes.Add("id", id);
//attributes.Add("style", "height:17px");
autocomplete.HtmlAttributes(attributes);
}
return autocomplete;
}
}
}