Exemple #1
0
        public static MvcHtmlString ExtTextBoxAddOnForEnable <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                              Expression <Func <TModel, TValue> > expression, CustomControlConstants.AddOn addOn, string target = null, object htmlAttributes = null, string format = null)
        {
            var html      = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);
            var maxLength = expression.MaxLength();

            if (maxLength != 0)
            {
                html = HtmlAttributeHelper.AddMaxLength(html, maxLength);
            }
            else
            {
                html = HtmlAttributeHelper.AddMaxLength(html, 255);
            }
            //html.Add("readonly", true);
            var textBox = "<div class='input-group'>";

            textBox += htmlHelper.TextBoxFor(expression, html).ToString();
            if (addOn == CustomControlConstants.AddOn.Search)
            {
                textBox +=
                    "<span class='input-group-addon' style='cursor: pointer' data-toggle='modal' data-target='" + target + "'><i class='fa fa-search'></i></span>";
            }
            textBox += "</div>";
            if (!string.IsNullOrEmpty(format))
            {
                return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                         htmlHelper.TextBoxFor(expression, format, html).ToString(), expression));
            }

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     textBox, expression));
        }
Exemple #2
0
        public static MvcHtmlString ExtTextAreaFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                    Expression <Func <TModel, TValue> > expression, object htmlAttributes = null)
        {
            var html = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);

            html = HtmlAttributeHelper.AddTextAreaStyle(html);
            var maxLength = expression.MaxLength();

            if (maxLength != 0)
            {
                html = HtmlAttributeHelper.AddMaxLength(html, maxLength);
            }

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     htmlHelper.TextAreaFor(expression, html).ToString(), expression));
        }
        public static MvcHtmlString ExtTextBoxNumberFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                         Expression <Func <TModel, TValue> > expression, object htmlAttributes = null, string format = null)
        {
            var html      = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);
            var maxLength = expression.MaxLength();

            if (maxLength != 0)
            {
                html = HtmlAttributeHelper.AddMaxLength(html, maxLength);
            }
            else
            {
                html = HtmlAttributeHelper.AddMaxLength(html, 255);
            }
            var stringBuilder = new StringBuilder();

            if (!string.IsNullOrEmpty(format))
            {
                stringBuilder.AppendLine(htmlHelper.TextBoxFor(expression, format, html).ToString());
            }
            else
            {
                stringBuilder.AppendLine(htmlHelper.TextBoxFor(expression, html).ToString());
            }

            var controlId = HtmlAttributeHelper.GetControlIdFromExpression(expression);

            stringBuilder.AppendLine("<script>$(function(){");
            stringBuilder.AppendLine("$('#" + controlId + "').keypress(function(event) {");
            // stringBuilder.AppendLine("var charCode = (event.which) ? event.which : event.keyCode;");
            stringBuilder.AppendLine("if (event.which != 8 && event.which != 0 && (event.which < 48 || event.which > 57)) {");
            stringBuilder.AppendLine("return false;");
            stringBuilder.AppendLine("}");
            stringBuilder.AppendLine("else {");
            stringBuilder.AppendLine("return true;");
            stringBuilder.AppendLine("};");
            stringBuilder.AppendLine("});");
            stringBuilder.AppendLine("});</script>");
            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     stringBuilder.ToString(), expression));
        }
Exemple #4
0
        public static MvcHtmlString ExtTextBoxFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                   Expression <Func <TModel, TValue> > expression, object htmlAttributes = null, string format = null)
        {
            var html      = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);
            var maxLength = expression.MaxLength();

            if (maxLength != 0)
            {
                html = HtmlAttributeHelper.AddMaxLength(html, maxLength);
            }
            else
            {
                html = HtmlAttributeHelper.AddMaxLength(html, 255);
            }

            if (!string.IsNullOrEmpty(format))
            {
                return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                         htmlHelper.TextBoxFor(expression, format, html).ToString(), expression));
            }

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     htmlHelper.TextBoxFor(expression, html).ToString(), expression));
        }
Exemple #5
0
        public static MvcHtmlString ExtNumberAddOnFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                       Expression <Func <TModel, TValue> > expression, CustomControlConstants.AddOn addOn, String textAddOn = null, NumberOption option = null, object htmlAttributes = null)
        {
            var html      = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);
            var maxLength = expression.MaxLength();

            if (maxLength != 0)
            {
                html = HtmlAttributeHelper.AddMaxLength(html, maxLength);
            }
            else
            {
                html = HtmlAttributeHelper.AddMaxLength(html, 255);
            }

            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("<div class='input-group padding-right-8'>");
            stringBuilder.AppendLine(htmlHelper.TextBoxFor(expression, html).ToString());
            switch (addOn)
            {
            case CustomControlConstants.AddOn.Text:
                stringBuilder.AppendLine(" <span class='input-group-addon'>" + textAddOn + "</span>");
                break;
            }
            stringBuilder.AppendLine("</div >");
            var controlId = HtmlAttributeHelper.GetControlIdFromExpression(expression);

            stringBuilder.AppendLine("<script>$(function(){");
            var options = new List <string>()
            {
                "aSep: ','",
                "aDec: '.'"
            };

            if (option != null)
            {
                if (option.Min.HasValue)
                {
                    options.Add(string.Format("vMin: '{0}'", option.Min.Value));
                }
                if (option.Max.HasValue)
                {
                    options.Add(string.Format("vMax: '{0}'", option.Max.Value));
                }
                else
                {
                    options.Add(string.Format("vMax: '{0}'", 9999999));
                }
                if (!string.IsNullOrEmpty(option.ASign))
                {
                    options.Add(string.Format("aSign: '{0}'", option.ASign));
                }
                if (!string.IsNullOrEmpty(option.PSign))
                {
                    options.Add(string.Format("pSign: '{0}'", option.PSign));
                }
                if (option.NumberOfDecimal.HasValue)
                {
                    options.Add(string.Format("mDec : {0}", option.NumberOfDecimal.Value));
                }
            }
            var optionsStr = string.Join(", ", options);

            stringBuilder.AppendLine(string.Format("$('#{0}').autoNumeric('init', {{{1}}});", controlId, optionsStr));
            stringBuilder.AppendLine("});</script>");
            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     stringBuilder.ToString(), expression));
        }
Exemple #6
0
        public static MvcHtmlString ExtNumberFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                  Expression <Func <TModel, TValue> > expression, NumberOption option = null, object htmlAttributes = null, bool showmessage = true)
        {
            var html      = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);
            var maxLength = expression.MaxLength();

            if (maxLength != 0)
            {
                html = HtmlAttributeHelper.AddMaxLength(html, maxLength);
            }
            else
            {
                html = HtmlAttributeHelper.AddMaxLength(html, 255);
            }

            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine(htmlHelper.TextBoxFor(expression, html).ToString());
            var controlId = HtmlAttributeHelper.GetControlIdFromExpression(expression);

            stringBuilder.AppendLine("<script>$(function(){");
            var options = new List <string>()
            {
                "aSep: ','",
                "aDec: '.'"
            };

            if (option != null)
            {
                if (option.Min.HasValue)
                {
                    options.Add(string.Format("vMin: '{0}'", option.Min.Value));
                }
                if (option.Max.HasValue)
                {
                    options.Add(string.Format("vMax: '{0}'", option.Max.Value));
                }
                else
                {
                    options.Add(string.Format("vMax: '{0}'", 9999999));
                }
                if (!string.IsNullOrEmpty(option.ASign))
                {
                    options.Add(string.Format("aSign: '{0}'", option.ASign));
                }
                if (!string.IsNullOrEmpty(option.PSign))
                {
                    options.Add(string.Format("pSign: '{0}'", option.PSign));
                }
                if (option.NumberOfDecimal.HasValue)
                {
                    options.Add(string.Format("mDec : {0}", option.NumberOfDecimal.Value));
                }
            }
            var optionsStr = string.Join(", ", options);

            stringBuilder.AppendLine(string.Format("$('#{0}').autoNumeric('init', {{{1}}});", controlId, optionsStr));
            stringBuilder.AppendLine("});</script>");
            if (showmessage)
            {
                return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                         stringBuilder.ToString(), expression));
            }
            else
            {
                return(new MvcHtmlString(stringBuilder.ToString()));
            }
        }