Esempio n. 1
0
        public static IHtmlContent TypeaheadFor <TModel, TValue>(this IHtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, IEnumerable source, object htmlAttributes = null)
        {
            var option = new TypeaheadOption();

            option.Source(source);
            return(html.TypeaheadFor(expression, option, htmlAttributes));
        }
Esempio n. 2
0
        public static IHtmlContent BsTypeaheadFor <TModel, TValue>(this IHtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, Dictionary <int, string> source, TypeaheadOption option, string icon = null, ComponentDirection?dir = null, int lable_col = 2, int editor_col = 4, object htmlAttribute = null)
        {
            string displayName = null;

            SetVariables(html, expression, ref displayName, out var style, out var dirName, out var label, out var validator, out _, lable_col, dir);
            var attributes = ComponentUtility.MergeAttributes(htmlAttribute, new { @class = "form-control", placeholder = displayName, dir = dirName, style });
            var editor     = html.TypeaheadFor(expression, source, option, attributes);
            var result     = SetTemplate(label, icon, editor_col, validator, editor.ToHtmlString(), dirName);

            return(new HtmlString(result));
        }
Esempio n. 3
0
        public static IHtmlContent TypeaheadFor <TModel, TValue>(this IHtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, TypeaheadOption option, object htmlAttributes = null)
        {
            var metadata      = html.GetModelExplorer(expression);
            var htmlFieldName = html.FieldNameFor(expression);
            var id            = html.FieldIdFor(expression);
            var name          = html.ViewData.TemplateInfo.GetFullHtmlFieldName(htmlFieldName);
            var value         = metadata.Model?.ToString() ?? "";

            option.Dictionary.TryGetValue(value, out var txtValue);
            var displayName = metadata.Metadata.DisplayName ?? metadata.Metadata.PropertyName ?? htmlFieldName.Split('.').Last();
            var mergAttr    = ComponentUtility.MergeAttributes(htmlAttributes, new { id = id + "_typeahead", @class = "form-control", placeholder = displayName, autocomplete = "off" });
            var textbox     = html.TextBox(name + "_typeahead", txtValue, mergAttr);
            var hidden      = html.HiddenFor(expression);

            html.ScriptOnce(ComponentUtility.GetJsTag(typeahead_js, null));
            option.OnSelect(@"function(item) {
                            if ( item.value != ""-21"") {
                                $(""#" + id + @""").val(item.value).trigger('change').valid();
                            }
                        }");
            html.Script(@"
            <script>
                $(function(){
                    $(""#" + id + @"_typeahead"").typeahead(" + option.RenderOptions() + @")
                    .keypress(function(){
                        $(""#" + id + @""").val('').trigger('change').valid();
                    });
                });
            </script>");
            return(new HtmlString(textbox.ToHtmlString() + hidden.ToHtmlString()));
        }
Esempio n. 4
0
 public static IHtmlContent TypeaheadFor <TModel, TValue>(this IHtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, Dictionary <int, string> source, TypeaheadOption option, object htmlAttributes = null)
 {
     option.Source(source);
     return(html.TypeaheadFor(expression, option, htmlAttributes));
 }