Exemple #1
0
        protected static HtmlTag ToggleInputRender(AdaptiveToggleInput toggleInput, AdaptiveRendererContext context)
        {
            var htmlLabelId = GenerateRandomId();

            var uiElement = new DivTag()
                            .AddClass("ac-input")
                            .Style("width", "100%");

            var uiCheckboxInput = new HtmlTag("input")
                                  .Attr("id", htmlLabelId)
                                  .Attr("type", "checkbox")
                                  .Attr("name", toggleInput.Id)
                                  .Attr("data-ac-valueOn", toggleInput.ValueOn ?? bool.TrueString)
                                  .Attr("data-ac-valueOff", toggleInput.ValueOff ?? bool.FalseString)
                                  .Style("display", "inline-block")
                                  .Style("vertical-align", "middle")
                                  .Style("margin", "0px");

            if (toggleInput.Value == toggleInput.ValueOn)
            {
                uiCheckboxInput.Attr("checked", string.Empty);
            }

            var uiLabel = CreateLabel(htmlLabelId, toggleInput.Title, context);

            return(uiElement.Append(uiCheckboxInput).Append(uiLabel));
        }
Exemple #2
0
        private static HtmlTag ChoiceSetRenderInternal(AdaptiveChoiceSetInput adaptiveChoiceSetInput, AdaptiveRendererContext context, string htmlInputType)
        {
            // the default values are specified by a comma separated string input.value
            var defaultValues = adaptiveChoiceSetInput.Value?.Split(',').Select(p => p.Trim()).Where(s => !string.IsNullOrEmpty(s)).ToList() ?? new List <string>();

            // render as a series of radio buttons
            var uiElement = new DivTag()
                            .AddClass("ac-input")
                            .Style("width", "100%");

            foreach (var choice in adaptiveChoiceSetInput.Choices)
            {
                var htmlLabelId = GenerateRandomId();

                var uiInput = new HtmlTag("input")
                              .Attr("id", htmlLabelId)
                              .Attr("type", htmlInputType)
                              .Attr("name", adaptiveChoiceSetInput.Id)
                              .Attr("value", choice.Value)
                              .Style("margin", "0px")
                              .Style("display", "inline-block")
                              .Style("vertical-align", "middle");


                if (defaultValues.Contains(choice.Value))
                {
                    uiInput.Attr("checked", string.Empty);
                }

                var uiLabel = CreateLabel(htmlLabelId, choice.Title, context);

                var compoundInputElement = new DivTag()
                                           .Append(uiInput)
                                           .Append(uiLabel);

                uiElement.Append(compoundInputElement);
            }

            return(uiElement);
        }
Exemple #3
0
        private static HtmlTag ChoiceSetRenderInternal(AdaptiveChoiceSetInput adaptiveChoiceSetInput, AdaptiveRenderContext context, string htmlInputType)
        {
            var defaultValues = ParseChoiceSetInputDefaultValues(adaptiveChoiceSetInput.Value);

            // render as a series of radio buttons
            var uiElement = new DivTag()
                            .AddClass("ac-input")
                            .Style("width", "100%");

            foreach (var choice in adaptiveChoiceSetInput.Choices)
            {
                var htmlLabelId = GenerateRandomId();

                var uiInput = new HtmlTag("input")
                              .Attr("id", htmlLabelId)
                              .Attr("type", htmlInputType)
                              .Attr("name", adaptiveChoiceSetInput.Id)
                              .Attr("value", choice.Value)
                              .Style("margin", "0px")
                              .Style("display", "inline-block")
                              .Style("vertical-align", "middle");

                // Only select an option if isMultiSelect is true (checkboxes)
                // or there is only one specified value
                if (defaultValues.Contains(choice.Value) && (adaptiveChoiceSetInput.IsMultiSelect || defaultValues.Count == 1))
                {
                    uiInput.Attr("checked", string.Empty);
                }

                var uiLabel = CreateLabel(htmlLabelId, choice.Title, context);

                var compoundInputElement = new DivTag()
                                           .Append(uiInput)
                                           .Append(uiLabel);

                uiElement.Append(compoundInputElement);
            }

            return(uiElement);
        }