Esempio n. 1
0
        public void Should_not_replace_existing_attributes()
        {
            IHtmlNode tag = new HtmlElement("div");
            tag.Attributes(new Dictionary<string, string> { { "class", "t-widget" } });
            tag.Attributes(new Dictionary<string, string> { { "class", "t-other" } }, false);

            Assert.Equal("t-widget", tag.Attribute("class"));
        }
        public IHtmlNode HiddenInputTag()
        {
            IHtmlNode input = new HtmlElement("input", TagRenderMode.SelfClosing)
                    .Attributes(new
                    {
                        type = "text",
                        style = "display:none"
                    });

            if (Component.Items.Any())
            {
                DropDownItem selectedItem = Component.Items[Component.SelectedIndex];
                input.Attribute("value", selectedItem.Value.HasValue() ? selectedItem.Value : selectedItem.Text);
            }

            if (Component.Name.HasValue())
            {
                input.Attributes(Component.GetUnobtrusiveValidationAttributes())
                     .Attributes(new
                     {
                         name = Component.GetName(string.Empty),
                         id = Component.Id
                     })
                     .Attributes(Component.HiddenInputHtmlAttributes);
            }

            return input;
        }
        /// <summary>
        /// Creates the file input element.
        /// </summary>
        /// <returns></returns>
        public IHtmlNode CreateFileInput()
        {
            var element = new HtmlElement("input", TagRenderMode.SelfClosing)
                .Attributes(new { type = "file", name = upload.Name, id = upload.Id });

            if (upload.HtmlAttributes.ContainsKey("accept"))
            {
                element.Attributes(new { accept = upload.HtmlAttributes["accept"].ToString().ToLowerInvariant() });
            }

            return element;
        }
Esempio n. 4
0
        public IHtmlNode CreateUpload()
        {
            var element = new HtmlElement("input", TagRenderMode.SelfClosing);
            var attributes = new Dictionary<string, object>
            {   { "type", "file" },
                { "name", upload.Name },
                { "id", upload.Id }
            };

            foreach (var attr in upload.HtmlAttributes)
            {
                attributes[attr.Key] = attr.Value;
            }

            element.Attributes(attributes);

            return element;
        }
        public IHtmlNode HiddenInputTag()
        {
            IHtmlNode input = new HtmlElement("input", TagRenderMode.SelfClosing)
                              .Attributes(new
                              {
                                  type = "text",
                                  style = "display:none"
                              });

            string value = string.Empty;
            if (Component.Items.Any())
            {
                value = Component.GetValue<string>(Component.Value);
                if (string.IsNullOrEmpty(value) && Component.SelectedIndex != -1)
                {
                    DropDownItem selectedItem = Component.Items[Component.SelectedIndex];
                    value = selectedItem.Value.HasValue() ? selectedItem.Value : selectedItem.Text;
                }
            }
            else if (Component.Name.HasValue() && Component.ViewContext.ViewData.ModelState.ContainsKey(Component.Name))
            {
                value = Component.GetValue<string>(null);
            }

            if (Component.Name.HasValue()) {
                string name = Component.GetName(string.Empty);

                input.Attributes(Component.GetUnobtrusiveValidationAttributes())
                     .Attributes(new
                     {
                         id = Component.Id,
                         name = name
                     });
            }

            input.ToggleAttribute("value", value, value.HasValue())
                 .Attributes(Component.HiddenInputHtmlAttributes);

            return input;
        }
Esempio n. 6
0
        public void Should_set_attributes_as_object()
        {
            IHtmlNode tag = new HtmlElement("div");
            tag.Attributes(new { @class = "t-widget" });

            Assert.Equal("t-widget", tag.Attribute("class"));
        }
Esempio n. 7
0
        public void Should_set_attributes_as_dictionary()
        {
            IHtmlNode tag = new HtmlElement("div");
            tag.Attributes(new Dictionary<string, string> { { "class", "t-widget" } });

            Assert.Equal("t-widget", tag.Attribute("class"));
        }