Esempio n. 1
0
        public static MvcHtmlString NumericBoxFor <TModel, TValue>(this HtmlHelper <TModel> helper,
                                                                   Expression <Func <TModel, TValue> > expression)
        {
            var build = new TagBuilder("input");

            build.Attributes.Add("type", "number");
            build.Attributes.Add("id", ExtensionFunctions.GetFieldName(expression));
            build.Attributes.Add("name", ExtensionFunctions.GetFieldName(expression).Replace("_", "."));
            return(new MvcHtmlString(build.ToString()));
        }
Esempio n. 2
0
        public static MvcHtmlString TimeBoxFor <TModel, TValue>(this HtmlHelper <TModel> helper,
                                                                Expression <Func <TModel, TValue> > expression, string pattern = "hh:mm:ss")
        {
            var div = new TagBuilder("div")
            {
                InnerHtml = string.Format("<input data-format=\"{0}\" type=\"time\" id=\"{1}\"></input>" +
                                          "<span class=\"add-on\"> <i data-time-icon=\"icon-time\" data-date-icon=\"icon-calendar\"></i>" +
                                          "</span>", pattern, ExtensionFunctions.GetFieldName(expression))
            };

            div.Attributes.Add("class", "bootstrap-timepicker");

            //var build = new TagBuilder("input");
            //build.Attributes.Add("type", "time");
            //build.Attributes.Add("class", "bootstrap-timepicker");
            //if (!string.IsNullOrEmpty(pattern))
            //{
            //    build.Attributes.Add("pattern", pattern);
            //}
            //build.Attributes.Add("id", ExtensionFunctions.GetFieldName(expression));
            return(new MvcHtmlString(div.ToString()));
        }
Esempio n. 3
0
        public static MvcHtmlString AutocompleteFor <TModel, TValue>(this HtmlHelper <TModel> helper,
                                                                     Expression <Func <TModel, TValue> > expression, string searchUrl)
        {
            var fieldName    = ExtensionFunctions.GetFieldName(expression);
            var hidden       = helper.HiddenFor(expression);
            var autoCompName = fieldName + "AutoComplete";
            var script       = new TagBuilder("script");

            script.Attributes.Add("type", "text/javascript");
            script.Attributes.Add("language", "javascript");
            script.InnerHtml = "$(function() {$('#" + autoCompName + "').autocomplete(" +
                               "{ focus: function(event, ui) {" +
                               "$('#" + autoCompName + "').val(ui.item.label); " +
                               "return false; }, select: function (evt, ui) {" +
                               "$(\"#" + fieldName + "\").val(ui.item.value); $('#" + autoCompName + "').val(ui.item.label);" +
                               "return false; }});})";
            var autoComplete = new TagBuilder("input");

            autoComplete.Attributes.Add("id", autoCompName);
            autoComplete.Attributes.Add("data-autocomplete", searchUrl);
            return(new MvcHtmlString(script + hidden.ToHtmlString() +
                                     autoComplete));
        }