Example #1
0
 /// <summary>
 /// Bootstrap and HTML 5 Text Box Helper
 /// </summary>
 /// <param name="htmlHelper">The HTML helper instance that this method extends.</param>
 /// <param name="expression">An expression that identifies the object that contains the properties to render.</param>
 /// <param name="type">The text type to set (text, password, date, tel, email, etc.).</param>
 /// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.</param>
 /// <returns>An HTML input element with the appropriate type set.</returns>
 public static MvcHtmlString TextBox5For <TModel, TValue>(
     this HtmlHelper <TModel> htmlHelper,
     Expression <Func <TModel, TValue> > expression,
     Html5InputTypes type,
     object htmlAttributes = null)
 {
     return(TextBox5For(htmlHelper, expression, type, string.Empty, string.Empty, false, false, false, htmlAttributes));
 }
Example #2
0
        /// <summary>
        /// Bootstrap and HTML 5 Text Box Helper
        /// </summary>
        /// <param name="htmlHelper">The HTML helper instance that this method extends.</param>
        /// <param name="expression">An expression that identifies the object that contains the properties to render.</param>
        /// <param name="type">The text type to set (text, password, date, tel, email, etc.).</param>
        /// <param name="title">The HTML 5 'title' attribute to set.</param>
        /// <param name="placeholder">The HTML 5 'placeholder' attribute to set.</param>
        /// <param name="isRequired">Whether or not to set the 'required' attribute on this text box.</param>
        /// <param name="isAutoFocus">Whether or not to set the 'autofocus' attribute on this text box.</param>
        /// <param name="isDisable">Whether or not to set the 'disable' attribute on this text box.</param>
        /// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.</param>
        /// <returns>An HTML input element with the appropriate type set.</returns>
        public static MvcHtmlString TextBox5For <TModel, TValue>(
            this HtmlHelper <TModel> htmlHelper,
            Expression <Func <TModel, TValue> > expression,
            Html5InputTypes type,
            string title,
            string placeholder,
            bool isRequired,
            bool isAutoFocus,
            bool isDisable,
            object htmlAttributes = null)
        {
            MvcHtmlString html = default(MvcHtmlString);
            Dictionary <string, object> attr = new Dictionary <string, object>();

            if (htmlAttributes != null)
            {
                var attributes =
                    HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
                foreach (var item in attributes)
                {
                    attr.Add(item.Key, item.Value);
                }
            }

            attr.Add("type", type.ToString());
            attr.Add("class", "form-control");
            if (!string.IsNullOrEmpty(title))
            {
                attr.Add("title", title);
            }
            if (!string.IsNullOrEmpty(placeholder))
            {
                attr.Add("placeholder", placeholder);
            }
            if (isAutoFocus)
            {
                attr.Add("autofocus", "autofocus");
            }
            if (isRequired)
            {
                attr.Add("required", "required");
            }
            if (isDisable)
            {
                attr.Add("disabled", "");
            }

            html = InputExtensions.TextBoxFor(htmlHelper,
                                              expression,
                                              attr);

            return(html);
        }
        public static MvcHtmlString FormGroupFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                  Expression <Func <TModel, TValue> > expression,
                                                                  bool autofocus        = false,
                                                                  Html5InputTypes type  = Html5InputTypes.Text,
                                                                  bool required         = false,
                                                                  string icon           = null,
                                                                  string cssClass       = null,
                                                                  object htmlAttributes = null
                                                                  )
        {
            TagBuilder formGroup = new TagBuilder("div");

            if (!string.IsNullOrWhiteSpace(cssClass))
            {
                if (cssClass.Contains("form-group"))
                {
                    formGroup.AddCssClass(cssClass);
                }
                else
                {
                    formGroup.AddCssClass("form-group " + cssClass);
                }
            }

            formGroup.AddCssClass("form-group");

            if (!string.IsNullOrEmpty(icon))
            {
                TagBuilder div = new TagBuilder("div");
                div.AddCssClass("icon-div");

                TagBuilder iconTb = new TagBuilder("i");
                iconTb.AddCssClass("icon-input");
                iconTb.AddCssClass(icon);

                div.InnerHtml = iconTb.ToString();

                formGroup.InnerHtml += div.ToString();
            }


            formGroup.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));

            ModelMetadata metadata      = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);
            string        htmlFieldName = ExpressionHelper.GetExpressionText(expression);
            string        labelText     = metadata.DisplayName ?? metadata.PropertyName ?? htmlFieldName.Split('.').Last();

            formGroup.InnerHtml += TextBoxHtmlExtention.TextBoxFor(htmlHelper, expression, labelText, string.Empty, autofocus, required, type);
            formGroup.InnerHtml += LabelForHtmlExtention.LabelFor(htmlHelper, expression);
            formGroup.InnerHtml += ValidationExtensions.ValidationMessageFor(htmlHelper, expression);

            return(MvcHtmlString.Create(formGroup.ToString()));
        }
Example #4
0
        public static MvcHtmlString TextBoxFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                Expression <Func <TModel, TValue> > expression,
                                                                string title          = null,
                                                                string placeholder    = null,
                                                                bool autofocus        = false,
                                                                bool required         = false,
                                                                Html5InputTypes type  = Html5InputTypes.Text,
                                                                string icon           = null,
                                                                object htmlAttributes = null
                                                                )
        {
            RouteValueDictionary rvd = new RouteValueDictionary(
                HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));

            rvd.Add("type", type.ToString());
            rvd.Add("class", "form-control");
            rvd.Add("stype", "text-align: center;");

            if (required)
            {
                rvd.Add("required", "");
            }

            if (!string.IsNullOrWhiteSpace(title))
            {
                rvd.Add("title", title);
            }

            if (!string.IsNullOrWhiteSpace(placeholder))
            {
                rvd.Add("placeholder", placeholder);
            }

            if (autofocus)
            {
                rvd.Add("autofocus", "");
            }

            if (!string.IsNullOrEmpty(icon))
            {
            }

            return(InputExtensions.TextBoxFor(htmlHelper, expression, rvd));
        }