private HtmlNodeElement GetFormButtons()
        {
            HtmlSelfClosingTagElement submit = new HtmlSelfClosingTagElement("input");

            submit.AddAttribute(new HtmlTypeAttribute("submit"));

            HtmlSelfClosingTagElement reset = new HtmlSelfClosingTagElement("input");

            reset.AddAttribute(new HtmlTypeAttribute("reset"));

            if (_options.SubmitButtonAttributes != null)
            {
                submit.AddRangeAttributes(_options.SubmitButtonAttributes);
            }

            if (_options.ResetButtonAttributes != null)
            {
                reset.AddRangeAttributes(_options.ResetButtonAttributes);
            }

            HtmlNodeElement wrapper = new HtmlNodeElement("span");

            wrapper.Append(submit);
            wrapper.Append(reset);

            return(wrapper);
        }
        internal HtmlNodeElement GenerateFormElement()
        {
            HtmlNodeElement formContent = new HtmlNodeElement("div");

            formContent.Children = GetHtmlFormGroups();

            HtmlNodeElement formFooter = new HtmlNodeElement("div");

            formFooter.Append(GetFormButtons());

            if (_options.FormFooterAttributes != null)
            {
                formFooter.AddRangeAttributes(_options.FormFooterAttributes);
            }

            if (_options != null && _options.FormFooterTemplateFunc != null)
            {
                formFooter = _options.FormFooterTemplateFunc(formFooter);
            }

            HtmlNodeElement form = new HtmlNodeElement("form");

            form.AddAttributeValue("action", _options.Action);
            form.Attributes = _options?.FormAttributes;
            form.Append(formContent);
            form.Append(formFooter);

            return(form);
        }
        private HtmlNodeElement GeRadioButtonsGroup(string name, IEnumerable <SelectListItem> values, string value, bool isMultiple = false)
        {
            HtmlNodeElement wrapper = new HtmlNodeElement("div");

            if (_options.RadioButtonsWrapperAttributes != null)
            {
                wrapper.AddRangeAttributes(_options.RadioButtonsWrapperAttributes);
            }

            foreach (var item in values)
            {
                HtmlNodeElement label = new HtmlNodeElement("label");
                label.Text(item.Text);

                if (_options.RadioButtonsGroupLabelAttributes != null)
                {
                    label.AddRangeAttributes(_options.RadioButtonsGroupLabelAttributes);
                }

                var radioInput = new HtmlSelfClosingTagElement("input")
                {
                    Attributes = new IHtmlAttribute[]
                    {
                        new HtmlAttribute("name", name),
                        new HtmlAttribute("value", item.Value),
                        new HtmlAttribute("type", isMultiple ? "checkbox" : "radio")
                    }
                };

                if (_options.RadioButtonsGroupInputAttributes != null)
                {
                    radioInput.AddRangeAttributes(_options.RadioButtonsGroupInputAttributes);
                }

                if (item.Selected || (value != null && item.Value == value.ToString()))
                {
                    radioInput.AddAttribute(new HtmlAttribute("checked"));
                }

                label.Append(radioInput);

                var div = new HtmlNodeElement("div");
                div.Append(label);

                if (_options.RadioButtonsGroupWrapperAttributes != null)
                {
                    div.AddRangeAttributes(_options.RadioButtonsGroupWrapperAttributes);
                }

                wrapper.Append(div);
            }

            return(wrapper);
        }
        public void Append_ShouldAppendChildAndSetHimParrent()
        {
            // Arrange
            HtmlNodeElement element = new HtmlNodeElement("div");

            // Act
            element.Append(new HtmlNodeElement("div"));

            // Assert
            Assert.NotNull(element.Children);
            Assert.NotEmpty(element.Children);
            Assert.Equal(element.UId, element.Children.FirstOrDefault().Parents.FirstOrDefault().UId);
        }
        private HtmlPairTagsElement GetFormGroup(PropertyInfo propInfo)
        {
            IHtmlElement    input        = GetProperInput(propInfo);
            HtmlNodeElement inputWrapper = new HtmlNodeElement("div");

            if (propInfo.GetCustomAttribute <HtmlInputAttribute>() != null)
            {
                input.AddAttribute(propInfo.GetCustomAttribute <HtmlInputAttribute>().Name);
            }

            inputWrapper.Append(input);
            // TODO Add validation element

            if (_options.InputWrapperAttributes != null)
            {
                inputWrapper.AddRangeAttributes(_options.InputWrapperAttributes);
            }

            HtmlNodeElement label = GetLabel(propInfo);

            HtmlNodeElement formGroup = new HtmlNodeElement("div");

            formGroup.Append(label);

            if (_options.FormGroupAttributes != null)
            {
                formGroup.AddRangeAttributes(_options.FormGroupAttributes);
            }

            formGroup.Append(inputWrapper);

            if (_options.FormGroupTemplateFunc != null)
            {
                formGroup = _options.FormGroupTemplateFunc(formGroup);
            }

            return(formGroup);
        }
        private HtmlNodeElement GetSelect(string name, IEnumerable <SelectListItem> values, string value, bool isMultiple = false)
        {
            HtmlNodeElement select = new HtmlNodeElement("select");

            select.AddAttribute(new HtmlNameAttribute(name));
            if (isMultiple)
            {
                select.AddAttribute("multiple");
            }

            if (_options.InputAttributes != null)
            {
                select.AddRangeAttributes(_options.InputAttributes);
            }

            foreach (var item in values)
            {
                var option = new HtmlPairTagsElement("option")
                {
                    Attributes = new IHtmlAttribute[]
                    {
                        new HtmlAttribute("value", item.Value)
                    }
                };

                option.Text(new HtmlString(item.Text));

                if (item.Selected || (value != null && item.Value == value.ToString()))
                {
                    option.AddAttribute("selected");
                }

                select.Append(option);
            }

            return(select);
        }