예제 #1
0
        public override string Render(IControl control, object htmlAttributes)
        {
            var id          = control.Name;
            var displayName = !string.IsNullOrEmpty(control.Label) ? control.Label : control.Name;

            var div = new MultiLevelTag("div");

            div.AddCssClass("form-inner");

            var items = control.DefaultValues;

            var count = 1;

            foreach (var innerItem in items)
            {
                var input = new MultiLevelTag("input");
                input.Attributes.Add("id", $"{id}_{count}");
                input.Attributes.Add("name", $"{id}");
                input.Attributes.Add("value", $"{innerItem.Key}");
                input.Attributes.Add("type", "checkbox");
                if (innerItem.Value)
                {
                    input.Attributes.Add("checked", null);
                }

                if (control.IsRequired)
                {
                    input.Attributes.Add("required", null);
                    input.Attributes.Add("minlength", "1");
                }

                CustomHtml(input, htmlAttributes);

                var label = new MultiLevelTag("label");
                label.Attributes.Add("for", $"{id}_{count}");
                label.SetInnerText(innerItem.Key);

                var checkboxDiv = new MultiLevelTag("div");
                checkboxDiv.AddCssClass("form-checkbox");

                checkboxDiv.Add(input);
                checkboxDiv.Add(label);

                div.Add(checkboxDiv);
                count++;
            }

            IsRequired(control, div, displayName);
            ExplanationText(control, div);
            ToolTip(control, div);

            return(div.ToString());
        }
예제 #2
0
        public override string Render(IControl control, object htmlAttributes)
        {
            var id = control.Name;

            var displayName = !string.IsNullOrEmpty(control.Label) ? control.Label : control.Name;

            var div = new MultiLevelTag("div");

            div.AddCssClass("form-inner");

            var input = new MultiLevelTag("input");

            input.Attributes.Add("id", $"{id}");
            input.Attributes.Add("name", id);
            input.Attributes.Add("type", "checkbox");
            input.Attributes.Add("value", $"{id}");
            CustomHtml(input, htmlAttributes);

            if (control.DefaultValue == "True")
            {
                input.Attributes.Add("checked", "");
            }

            IsRequired(control, input, displayName);

            foreach (var validation in control.Validation)
            {
                input.Attributes.Add($"data-rule-{validation.ValidationRule}", validation.ValidationValue);
                input.Attributes.Add($"data-msg-{validation.ValidationRule}", validation.ValidationErrorMessage);
            }

            var required = control.IsRequired ? " form-label--required" : string.Empty;
            var label    = new MultiLevelTag("label");

            label.Attributes.Add("for", $"{id}");
            label.SetInnerText(displayName);
            label.Attributes.Add("class", $"form-label{required}");


            div.Add(input);
            div.Add(label);

            ExplanationText(control, div);
            ToolTip(control, input);

            return(div.ToString());
        }
        public static IHtmlString SubmitButton(this KenticoForm html, string submitText, object htmlAttributes)
        {
            var tag = new MultiLevelTag("button");

            tag.Attributes.Add("type", "submit");
            tag.Attributes.Add("data-submit", null);
            tag.SetInnerText(submitText);

            if (htmlAttributes != null)
            {
                var customAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
                if (customAttributes != null)
                {
                    foreach (var item in customAttributes.Where(item => !tag.Attributes.ContainsKey(item.Key)))
                    {
                        tag.Attributes.Add(item.Key, item.Value.ToString());
                    }
                }
            }

            tag.AddCssClass("button");

            return(MvcHtmlString.Create(tag.ToString()));
        }