예제 #1
0
        public void Should_attribute_replaces_by_default()
        {
            IHtmlNode tag = new HtmlElement("div");

            tag.Attribute("class", "t-widget");
            tag.Attribute("class", "t-other");

            Assert.Equal("t-other", 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;
        }
예제 #3
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"));
        }
예제 #4
0
        public void Should_prepend_css_classes()
        {
            IHtmlNode tag = new HtmlElement("div").AddClass("test").PrependClass("first second");

            Assert.Equal("first second test", tag.Attribute("class"));
        }
예제 #5
0
 public void Should_add_class()
 {
     IHtmlNode tag = new HtmlElement("div");
     tag.AddClass("t-widget");
     Assert.Equal("t-widget", tag.Attribute("class"));
 }
예제 #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"));
        }
예제 #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"));
        }
        public IHtmlNode InnerContentTag()
        {
            IHtmlNode root = new HtmlElement("div").AddClass("t-dropdown-wrap t-state-default");

            IHtmlNode input = new HtmlElement("input", TagRenderMode.SelfClosing)
                              .Attributes(new { type = "text"})
                              .ToggleAttribute("disabled", "disabled", !Component.Enabled)
                              .ToggleClass("input-validation-error", !Component.IsValid())
                              .PrependClass(UIPrimitives.Input)
                              .AppendTo(root);

            string name = string.Empty;
            if (Component.Name.HasValue())
            {
                name = Component.GetName("-input");
            }

            string text = Component.GetValue<string>(Component.Value);
            if (!Component.Items.Any())
            {
                text = Component.GetValue<string>(name, null);
                if (string.IsNullOrEmpty(text))
                {
                    try
                    {
                        text = Component.ViewContext.Controller.ValueOf<string>(name);
                    }
                    catch (System.Web.HttpRequestValidationException)
                    {
                        text = string.Empty;
                    }
                }
            }
            else if (Component.SelectedIndex != -1)
            {
                text = Component.Items[Component.SelectedIndex].Text;
                if (Component.Encoded)
                {
                    text = System.Web.HttpUtility.HtmlDecode(text);
                }
            }

            input.Attribute("id", Component.Id + "-input")
                 .ToggleAttribute("name", name, name.HasValue())
                 .ToggleAttribute("value", text, text.HasValue())
                 .Attributes(Component.InputHtmlAttributes);

            IHtmlNode link = new HtmlElement("span").AddClass("t-select", UIPrimitives.Header);

            new HtmlElement("span").AddClass(UIPrimitives.Icon, "t-arrow-down").Html("select").AppendTo(link);

            link.AppendTo(root);

            return root;
        }