public void TextAreaWithEmptyNameThrows()
        {
            // Arrange
            HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());

            // Act and assert
            ExceptionAssert.ThrowsArgumentException(() => helper.TextArea(null), "name", "Value cannot be null or an empty string.");

            // Act and assert
            ExceptionAssert.ThrowsArgumentException(() => helper.TextArea(String.Empty), "name", "Value cannot be null or an empty string.");
        }
        public void TextAreaWithEmptyNameThrows()
        {
            // Arrange
            HtmlHelper helper = HtmlHelperFactory.Create();

            // Act and assert
            Assert.ThrowsArgument(() => helper.TextArea(null), "name", "Value cannot be null or an empty string.");

            // Act and assert
            Assert.ThrowsArgument(() => helper.TextArea(String.Empty), "name", "Value cannot be null or an empty string.");
        }
Example #3
0
        public static MvcHtmlString TinyMce
            (this HtmlHelper htmlHelper, string name, string value, IDictionary <string, object> options)
        {
            var textArea =
                htmlHelper.TextArea(name, value, new { @id = name });

            var sync =
                new { setup = new JRaw("function (editor) { editor.on('change', function () { editor.save(); }) }") };

            var merged =
                JObject.FromObject(options);

            merged.Merge(JObject.FromObject(sync));

            var settings =
                (options == null) ? string.Empty : JsonConvert.SerializeObject(merged);

            var script = new TagBuilder("script");

            script.Attributes["type"] = "text/javascript";

            script.InnerHtml = @"
                    $(function() {
                        $('#" + name + "').tinymce(" + settings + @");
                    });";

            return(MvcHtmlString.Create(textArea + script.ToString()));
        }
        /// <summary>
        /// 具有不可用效果的多行文本框
        /// </summary>
        /// <param name="htmlHelper"></param>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="isReadonly"></param>
        /// <param name="dic"></param>
        /// <returns></returns>
        public static MvcHtmlString TextareaReadonly(this HtmlHelper htmlHelper, string name, object value = null, bool isReadonly = false, IDictionary <string, object> dic = null)
        {
            if (dic == null)
            {
                dic = new Dictionary <string, object>();
            }
            if (isReadonly)
            {
                if (dic.Keys.Contains("style"))
                {
                    string strStyle = dic["style"].ToString();
                    if (strStyle.Length > 0 && strStyle[dic["style"].ToString().Length - 1] != ';')
                    {
                        strStyle = strStyle + ";";
                    }
                    dic["style"] = strStyle + "background-color:#efefef;";
                }
                else
                {
                    dic.Add("style", "background-color:#efefef;");
                }

                dic.Add("readonly", isReadonly.ToString());
            }
            return(htmlHelper.TextArea(name, value.ToString(), dic));
        }
 public static MvcHtmlString TextArea(this HtmlHelper htmlHelper, string name, string value = null, string accessKey = null, string cssClass = null, int?cols = null, string dir = null, bool disabled = false, string id = null, string lang = null, bool readOnly = false, int?rows = null, string style = null, int?tabIndex = null, string title = null)
 {
     return(htmlHelper.TextArea(
                name,
                value,
                TextAreaAttributes(accessKey, cssClass, cols, dir, disabled, id, lang, readOnly, rows, style, tabIndex, title)));
 }
        public override MvcHtmlString WriteInput(HtmlHelper helper, object htmlAttributes)
        {
            IDictionary <string, object> efHtmlAttributes = new RouteValueDictionary(htmlAttributes);

            AddCommonHtmlAttributes(efHtmlAttributes);
            return(helper.TextArea(this.InputName, this.Value, efHtmlAttributes));
        }
        public void TextAreaAddsUnobtrusiveValidationAttributes()
        {
            // Arrange
            const string fieldName            = "name";
            var          modelStateDictionary = new ModelStateDictionary();
            var          validationHelper     = new ValidationHelper(
                new Mock <HttpContextBase>().Object,
                modelStateDictionary
                );
            HtmlHelper helper = HtmlHelperFactory.Create(modelStateDictionary, validationHelper);

            // Act
            validationHelper.RequireField(fieldName, "Please specify a valid Name.");
            validationHelper.Add(
                fieldName,
                Validator.StringLength(30, errorMessage: "Name cannot exceed {0} characters")
                );
            var html = helper.TextArea(
                fieldName,
                htmlAttributes: new Dictionary <string, object> {
                { "data-some-val", "5" }
            }
                );

            // Assert
            Assert.Equal(
                @"<textarea cols=""20"" data-some-val=""5"" data-val=""true"" data-val-length=""Name cannot exceed 30 characters"" data-val-length-max=""30"" data-val-required=""Please specify a valid Name."" id=""name"" name=""name"" rows=""2""></textarea>",
                html.ToString()
                );
        }
Example #8
0
        /// <summary>
        /// TextArea chỉ có thuộc tính Name
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static MvcHtmlString VnrTextArea(this HtmlHelper helper, string name)
        {
            var result = new StringBuilder();

            result.Append(helper.TextArea(name, new { @class = "k-textbox", style = "width:300px; height: 65px" }));
            return(MvcHtmlString.Create(result.ToString()));
        }
        /// <summary>
        /// 输出UMditor编辑器
        /// </summary>
        /// <param name="htmlHelper"></param>
        /// <param name="name"></param>
        /// <param name="tenantTypeId"></param>
        /// <param name="associateId"></param>
        /// <param name="value"></param>
        /// <param name="htmlAttributes"></param>
        /// <returns></returns>
        public static MvcHtmlString UMditor(this HtmlHelper htmlHelper, string name, string tenantTypeId, long associateId = 0, string value = null, Dictionary <string, object> htmlAttributes = null)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("参数名不能为空", "argsname is null");
            }
            htmlHelper.Script("~/Bundle/Scripts/UMditor");
            htmlHelper.Script("~/Bundle/Scripts/AtUser");


            string imageHtml = htmlHelper.Hidden("list-images", SiteUrls.Instance()._ImageManage(tenantTypeId, associateId)).ToHtmlString();

            TagBuilder builder = new TagBuilder("span");
            Dictionary <string, object> htmlAttrs = new Dictionary <string, object>();

            if (htmlAttributes != null)
            {
                htmlAttrs = new Dictionary <string, object>(htmlAttributes);
            }
            var data = new Dictionary <string, object>();

            data.Add("tenantTypeId", tenantTypeId);
            data.Add("associateId", associateId);
            htmlAttrs.Add("data", JsonConvert.SerializeObject(data));
            htmlAttrs.Add("plugin", "ueditor");
            builder.InnerHtml = htmlHelper.TextArea(name, value ?? string.Empty, htmlAttrs).ToString();
            return(MvcHtmlString.Create(builder.ToString() + imageHtml));
        }
        public static string RenderTextArea(HtmlHelper html, BootstrapTextAreaModel model)
        {
            if (model == null || string.IsNullOrEmpty(model.htmlFieldName))
            {
                return(null);
            }

            string validationMessage = "";

            if (model.displayValidationMessage)
            {
                string validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
                validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString();
            }
            model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));
            if (!string.IsNullOrEmpty(model.id))
            {
                model.htmlAttributes.AddOrReplace("id", model.id);
            }
            if (model.tooltipConfiguration != null)
            {
                model.htmlAttributes.MergeHtmlAttributes(model.tooltipConfiguration.ToDictionary());
            }
            return(html.TextArea(model.htmlFieldName, model.value, model.rows, model.columns, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString() + validationMessage);
        }
Example #11
0
        public void TextAreaParameterDictionaryMerging_Unobtrusive()
        {
            // Arrange
            HtmlHelper helper = MvcHelper.GetHtmlHelper();

            helper.ViewContext.ClientValidationEnabled      = true;
            helper.ViewContext.UnobtrusiveJavaScriptEnabled = true;
            helper.ViewContext.FormContext     = new FormContext();
            helper.ClientValidationRuleFactory = (name, metadata) =>
                                                 new[]
            {
                new ModelClientValidationRule
                {
                    ValidationType = "type",
                    ErrorMessage   = "error"
                }
            };

            // Act
            MvcHtmlString html = helper.TextArea("foo", new { rows = "30" });

            // Assert
            Assert.Equal(
                "<textarea cols=\"20\" data-val=\"true\" data-val-type=\"error\" id=\"foo\" name=\"foo\" rows=\"30\">"
                + Environment.NewLine
                + "</textarea>",
                html.ToHtmlString()
                );
        }
Example #12
0
    public static MvcHtmlString AcknowledgeTextArea <TModel, TProperty>(this HtmlHelper <TModel> helper, string name, string value, int rows, int columns, object containerHtmlAttributes = null, object inputHtmlAttributes = null, string dataType = "text")
    {
        IDictionary <string, object> containerAttribs = HtmlHelper.AnonymousObjectToHtmlAttributes(containerHtmlAttributes);

        if (containerAttribs == null)
        {
            containerAttribs = new Dictionary <string, object>();
        }

        IDictionary <string, object> inputAttribs = HtmlHelper.AnonymousObjectToHtmlAttributes(inputHtmlAttributes);

        if (inputAttribs == null)
        {
            inputAttribs = new Dictionary <string, object>();
        }
        inputAttribs.Add("data-type", dataType);

        TagBuilder containerBuilder = new TagBuilder("div");

        containerBuilder.MergeAttributes(containerAttribs);
        containerBuilder.Attributes.Add("data-role", "acknowledge-input");
        containerBuilder.AddCssClass("input-append");
        containerBuilder.InnerHtml = helper.TextArea(name, value, rows, columns, inputAttribs).ToHtmlString() + "<div data-role='acknowledgement'><i></i></div>";

        return(new MvcHtmlString(containerBuilder.ToString()));
    }
Example #13
0
        public static MvcHtmlString EATextArea(this HtmlHelper html, string id, string editorClass = "", string label = "")
        {
            var textBoxFor = html.TextArea(id, "", new { @type = "text", @class = "form-control" });

            label = TextUnBound(id, label);
            return(new MvcHtmlString(FetchStdFormWrappers(textBoxFor, MvcHtmlString.Empty, label, editorClass)));
        }
Example #14
0
        public static MvcHtmlString EATextAreaP(this HtmlHelper html, string id, string editorClass = "", string label = "")
        {
            var textBoxFor = html.TextArea(id, "", new { @type = "text", @class = "form-control form-control-sm" });

            label = TextUnBound(id, label);
            return(new MvcHtmlString(textBoxFor.ToHtmlString()));
        }
        private static String RenderElementByType(HtmlHelper html, FormElement model, String elementName, String elementValue)
        {
            var builder = new StringBuilder();
            switch (model.Type)
            {
                case FormElementType.TextField:
                    {
                        builder.Append(html.Encode(model.Title));
                        break;
                    }
                case FormElementType.TextBox:
                    {
                        builder.Append(html.Label(elementName, model.Title));
                        builder.Append("<br/>");
                        builder.Append(html.TextBox(elementName, elementValue));
                        break;
                    }
                case FormElementType.TextArea:
                    {
                        builder.Append(html.Label(elementName, model.Title));
                        builder.Append("<br/>");
                        builder.Append(html.TextArea(elementName, elementValue));
                        break;
                    }
                case FormElementType.CheckBox:
                    {
                        builder.Append(html.SimpleCheckBox(elementName, FormCollectionExtensions.BooleanValue(elementValue)));
                        builder.Append(html.Label(elementName, model.Title));
                        break;
                    }
                case FormElementType.DropDownList:
                    {
                        builder.Append(html.Label(elementName, model.Title));
                        builder.Append("<br/>");
                        builder.Append(html.DropDownList(elementName, ParseElementValuesForDropDown(model.ElementValues, elementValue)));
                        break;
                    }
                case FormElementType.RadioButtons:
                    {
                        builder.Append(html.Label(elementName, model.Title));
                        builder.Append("<br/>");
                        builder.Append(html.RadioList(elementName, ParseElementValuesForRadioButtons(model.ElementValues, elementName), elementValue));
                        break;
                    }
                case FormElementType.Captcha:
                    {
                        builder.Append(html.CaptchaImage(CaptchaDefaultHeight, CaptchaDefaultWidth));
                        builder.Append(html.Label(elementName, String.Empty));
                        builder.Append("<br/>");
                        builder.Append(html.CaptchaTextBox(elementName));
                        break;
                    }

                default:
                    break;
            }

            return builder.ToString();
        }
        public static MvcHtmlString CTextArea(
            this HtmlHelper html,
            string name,
            object htmlAttributes = null)
        {
            AddCustomClass(htmlAttributes, out IDictionary <string, object> attributes, "form-control");

            return(html.TextArea(name, attributes));
        }
Example #17
0
        /// <summary>输出字符串</summary>
        /// <param name="Html"></param>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="length"></param>
        /// <param name="htmlAttributes"></param>
        /// <returns></returns>
        public static MvcHtmlString ForString(this HtmlHelper Html, String name, String value, Int32 length = 0, Object htmlAttributes = null)
        {
            var atts = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

            //if (!atts.ContainsKey("class")) atts.Add("class", "col-xs-10 col-sm-5");
            //if (!atts.ContainsKey("class")) atts.Add("class", "col-xs-12 col-sm-8 col-md-6 col-lg-4");
            if (!atts.ContainsKey("class"))
            {
                atts.Add("class", "form-control");
            }

            // 首先输出图标
            var ico = "";

            MvcHtmlString txt = null;

            if (name.EqualIgnoreCase("Pass", "Password"))
            {
                txt = Html.Password(name, (String)value, atts);
            }
            else if (name.EqualIgnoreCase("Phone"))
            {
                ico = "<span class=\"input-group-addon\"><i class=\"glyphicon glyphicon-phone-alt\"></i></span>";
                if (!atts.ContainsKey("type"))
                {
                    atts.Add("type", "tel");
                }
                txt = Html.TextBox(name, value, atts);
            }
            else if (name.EqualIgnoreCase("email", "mail"))
            {
                ico = "<span class=\"input-group-addon\"><i class=\"glyphicon glyphicon-envelope\"></i></span>";
                if (!atts.ContainsKey("type"))
                {
                    atts.Add("type", "email");
                }
                txt = Html.TextBox(name, value, atts);
            }
            else if (name.EndsWithIgnoreCase("url"))
            {
                ico = "<span class=\"input-group-addon\"><i class=\"glyphicon glyphicon-home\"></i></span>";
                //if (!atts.ContainsKey("type")) atts.Add("type", "url");
                txt = Html.TextBox(name, value, atts);
            }
            else if (length < 0 || length > 300)
            {
                txt = Html.TextArea(name, value, atts);
            }
            else
            {
                txt = Html.TextBox(name, value, atts);
            }
            var icog = "<div class=\"input-group\">{0}</div>";
            var html = !String.IsNullOrWhiteSpace(ico) ? String.Format(icog, ico.ToString() + txt.ToString()) : txt.ToString();

            return(new MvcHtmlString(html));
        }
Example #18
0
        public static MvcHtmlString TextArea(this HtmlHelper htmlHelper, string name, string value, Property property, IDictionary <string, object> htmlAttributes)
        {
            // create own metadata based on PropertyViewModel
            var metadata             = new ModelMetadata(ModelMetadataProviders.Current, property.Entity.Type, null, property.PropertyType, property.Name);
            var validationAttributes = htmlHelper.GetUnobtrusiveValidationAttributes(name, metadata);

            htmlAttributes = PrepareHtmlAttributes(htmlAttributes, validationAttributes);

            return(htmlHelper.TextArea(name, value, htmlAttributes));
        }
Example #19
0
        public void TextAreaWithEmptyNameThrows()
        {
            // Arrange
            HtmlHelper helper = MvcHelper.GetHtmlHelper();

            // Act & Assert
            Assert.ThrowsArgumentNullOrEmpty(
                delegate { helper.TextArea(String.Empty); },
                "name");
        }
Example #20
0
        MvcHtmlString ICustomFieldRender <SimpleMultiLineFieldType> .RenderHtmlEditor <TModel>(HtmlHelper <TModel> html, IField field, IDictionary <string, object> htmlAttributes, params object[] additionalParameters)
        {
            if (htmlAttributes == null)
            {
                htmlAttributes = new Dictionary <string, object>();
            }
            if (!string.IsNullOrEmpty(field.alias))
            {
                htmlAttributes["class"] = (htmlAttributes.GetValueOrDefault("class", null) ?? "") + " FieldAlias_" + field.alias;
            }

            var value = (field as FieldData)?.ToString();

#if NETFULL
            return(html.TextArea($"fieldValue_{field.IdField}", value, htmlAttributes));
#elif NETCORE
            return(html.TextArea($"fieldValue_{field.IdField}", value, 0, 0, htmlAttributes));
#endif
        }
        public void TextAreaWithNonZeroRowsAndColumns()
        {
            // Arrange
            HtmlHelper helper = HtmlHelperFactory.Create();

            // Act
            var html = helper.TextArea("foo", null, 4, 10, null);

            // Assert
            Assert.Equal(@"<textarea cols=""10"" id=""foo"" name=""foo"" rows=""4""></textarea>", html.ToHtmlString());
        }
        public void TextAreaWithDefaultRowsAndCols()
        {
            // Arrange
            HtmlHelper helper = HtmlHelperFactory.Create();

            // Act
            var html = helper.TextArea("foo");

            // Assert
            Assert.Equal(@"<textarea cols=""20"" id=""foo"" name=""foo"" rows=""2""></textarea>", html.ToHtmlString());
        }
Example #23
0
        public static string TextAreaFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, int rows, int columns, IDictionary <string, object> htmlAttributes) where TModel : class
        {
            string inputName = ExpressionHelper.GetInputName(expression);

            // REVIEW:  We may not want to actually use the expression to get the default value.
            //          For example, if the property is an Int32, we may want to render blank, not 0.
            //          Consider checking the modelstate first for a value, before we get the value from the expression.
            TProperty value = GetValue(htmlHelper, expression);

            return(htmlHelper.TextArea(inputName, Convert.ToString(value, CultureInfo.CurrentCulture), rows, columns, htmlAttributes));
        }
Example #24
0
        public void TextAreaWithOutOfRangeRowsThrows()
        {
            // Arrange
            HtmlHelper helper = MvcHelper.GetHtmlHelper();

            // Act & Assert
            Assert.ThrowsArgumentOutOfRange(
                delegate { helper.TextArea("Foo", null /* value */, -1, 0, null /* htmlAttributes */); },
                "rows",
                @"The value must be greater than or equal to zero.");
        }
        public void TextAreaWithDefaultRowsAndCols()
        {
            // Arrange
            HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());

            // Act
            var html = helper.TextArea("foo");

            // Assert
            Assert.AreEqual(@"<textarea cols=""20"" id=""foo"" name=""foo"" rows=""2""></textarea>", html.ToHtmlString());
        }
        public void TextAreaWithNonZeroRowsAndColumns()
        {
            // Arrange
            HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());

            // Act
            var html = helper.TextArea("foo", null, 4, 10, null);

            // Assert
            Assert.AreEqual(@"<textarea cols=""10"" id=""foo"" name=""foo"" rows=""4""></textarea>", html.ToHtmlString());
        }
Example #27
0
        public void TextAreaParameterDictionaryMergingExplicitParameters()
        {
            // Arrange
            HtmlHelper helper = MvcHelper.GetHtmlHelper();

            // Act
            MvcHtmlString html = helper.TextArea("foo", "bar", 10, 25, new { rows = "30" });

            // Assert
            Assert.Equal(@"<textarea cols=""25"" id=""foo"" name=""foo"" rows=""10"">
bar</textarea>", html.ToHtmlString());
        }
Example #28
0
        public void TextAreaWithViewDataErrors()
        {
            // Arrange
            HtmlHelper helper = MvcHelper.GetHtmlHelper(GetTextAreaViewDataWithErrors());

            // Act
            MvcHtmlString html = helper.TextArea("foo", _textAreaAttributesObjectDictionary);

            // Assert
            Assert.Equal(@"<textarea class=""input-validation-error"" cols=""12"" id=""foo"" name=""foo"" rows=""15"">
AttemptedValueFoo</textarea>", html.ToHtmlString());
        }
Example #29
0
        public void TextAreaWithViewDataErrorsAndCustomClass()
        {
            // Arrange
            HtmlHelper helper = MvcHelper.GetHtmlHelper(GetTextAreaViewDataWithErrors());

            // Act
            MvcHtmlString html = helper.TextArea("foo", new { @class = "foo-class" });

            // Assert
            Assert.Equal(@"<textarea class=""input-validation-error foo-class"" cols=""20"" id=""foo"" name=""foo"" rows=""2"">
AttemptedValueFoo</textarea>", html.ToHtmlString());
        }
Example #30
0
        public void TextAreaWithNullValue()
        {
            // Arrange
            HtmlHelper helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());

            // Act
            MvcHtmlString html = helper.TextArea("foo", null, null);

            // Assert
            Assert.Equal(@"<textarea cols=""20"" id=""foo"" name=""foo"" rows=""2"">
ViewDataFoo</textarea>", html.ToHtmlString());
        }
Example #31
0
        public void TextAreaWithNoValueAndObjectAttributes()
        {
            // Arrange
            HtmlHelper helper = MvcHelper.GetHtmlHelper(GetTextAreaViewData());

            // Act
            MvcHtmlString html = helper.TextArea("baz", _textAreaAttributesObjectDictionary);

            // Assert
            Assert.Equal(@"<textarea cols=""12"" id=""baz"" name=""baz"" rows=""15"">
</textarea>", html.ToHtmlString());
        }
        public static string RenderTextArea(HtmlHelper html, BootstrapTextAreaModel model)
        {
            if (model == null || string.IsNullOrEmpty(model.htmlFieldName)) return null;

            string validationMessage = "";
            if (model.displayValidationMessage)
            {
                string validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
                validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString();
            }
            if(!string.IsNullOrEmpty(model.id)) model.htmlAttributes.AddOrReplace("id", model.id);
            if (model.tooltipConfiguration != null) model.htmlAttributes.AddRange(model.tooltipConfiguration.ToDictionary());
            return html.TextArea(model.htmlFieldName, model.value, model.rows, model.columns, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString() + validationMessage;
        }
 /// <summary>
 /// Renders the specified HTML.
 /// </summary>
 /// <param name="html">The HTML helper.</param>
 /// <param name="name">The element name.</param>
 /// <param name="value">The element value.</param>
 /// <param name="values">The element values.</param>
 /// <returns>Returns element html code.</returns>
 public override string Render(HtmlHelper html, String name, String value, String values)
 {
     return html.TextArea(name, value).ToString();
 }
 internal static string MultilineTextTemplate(HtmlHelper html)
 {
     return html.TextArea(String.Empty,
                          html.ViewContext.ViewData.TemplateInfo.FormattedModelValue.ToString(),
                          0 /* rows */, 0 /* columns */,
                          CreateHtmlAttributes(html, "text-box multi-line")).ToHtmlString();
 }
 public override MvcHtmlString WriteInput(HtmlHelper helper, object htmlAttributes)
 {
     IDictionary<string, object> efHtmlAttributes = new RouteValueDictionary(htmlAttributes);
     AddCommonHtmlAttributes(efHtmlAttributes);
     return helper.TextArea(this.InputName, this.Value, efHtmlAttributes);
 }