Exemple #1
0
        /// <inheritdoc/>
        protected override void BuildRenderInput(RenderTreeBuilder builder)
        {
            RefreshState();

            if (itemsToRender.Count > 0)
            {
                UglyHack uglyHack = new UglyHack();                 // see comment below

                foreach (var item in itemsToRender)
                {
                    TValue value = SelectorHelpers.GetValue <TItem, TValue>(ValueSelector, item);

                    builder.OpenComponent(1, typeof(HxInputCheckbox));

                    builder.AddAttribute(2, nameof(HxInputCheckbox.Label), SelectorHelpers.GetText(TextSelector, item));
                    builder.AddAttribute(3, nameof(HxInputCheckbox.Value), Value?.Contains(value) ?? false);
                    builder.AddAttribute(4, nameof(HxInputCheckbox.ValueChanged), EventCallback.Factory.Create <bool>(this, @checked => HandleValueChanged(@checked, item)));
                    builder.AddAttribute(5, nameof(HxInputCheckbox.Enabled), EnabledEffective);

                    // We need ValueExpression. Ehm, HxInputCheckbox needs ValueExpression. Because it is InputBase<T> which needs ValueExpression.
                    // We have nothing to give the HxInputCheckbox. So we make own class with property which we assign to the ValueExpression.
                    // Impacts? Unknown. Maybe none.
                    builder.AddAttribute(6, nameof(HxInputCheckbox.ValueExpression), (Expression <Func <bool> >)(() => uglyHack.HackProperty));

                    builder.AddAttribute(7, nameof(HxInputCheckbox.ShowValidationMessage), false);
                    builder.AddAttribute(8, nameof(HxInputCheckbox.Inline), this.Inline);

                    builder.AddMultipleAttributes(100, this.AdditionalAttributes);

                    builder.CloseComponent();
                }
            }
        }
 public void SelectorHelpers_GetText()
 {
     Assert.AreEqual("X1", SelectorHelpers.GetText <int>(i => "X" + i, 1));   // use text selector
     Assert.AreEqual("1", SelectorHelpers.GetText <int>(null, 1));            // text selector is null, use fallback (1.ToString())
     Assert.AreEqual("", SelectorHelpers.GetText <int?>(null, null));         // no text selector, no item, use empty string
     Assert.AreEqual("", SelectorHelpers.GetText <int>(i => null, 1));        // text selector is not null, do not use fallback (1.ToString())
 }
Exemple #3
0
 protected override void RenderChipValue(RenderTreeBuilder builder)
 {
     if ((chipValue is null) && (Value != null) && (DataImpl != null))
     {
         // fallback for initial rendering without chipValue
         // does not help when DataImpl is not set yet (loaded asynchronously)
         var item = DataImpl.FirstOrDefault(item => comparer.Equals(Value, SelectorHelpers.GetValue <TItem, TValue>(ValueSelectorImpl, item)));
         chipValue = SelectorHelpers.GetText(TextSelectorImpl, item);
     }
     builder.AddContent(0, chipValue);
 }
Exemple #4
0
        protected void BuildRenderInput_RenderRadioItem(RenderTreeBuilder builder, int index)
        {
            var item = itemsToRender[index];

            if (item != null)
            {
                bool selected = (index == selectedItemIndex);
                if (selected)
                {
                    chipValue = SelectorHelpers.GetText(TextSelectorImpl, item);
                }

                string inputId = GroupName + "_" + index.ToString();

                builder.OpenElement(100, "div");

                // TODO CoreCssClass
                builder.AddAttribute(101, "class", CssClassHelper.Combine("form-check", this.Inline ? "form-check-inline" : null));

                builder.OpenElement(200, "input");
                builder.AddAttribute(201, "class", "form-check-input");
                builder.AddAttribute(202, "type", "radio");
                builder.AddAttribute(203, "name", GroupName);
                builder.AddAttribute(204, "id", inputId);
                builder.AddAttribute(205, "value", index.ToString());
                builder.AddAttribute(206, "checked", selected);
                builder.AddAttribute(207, "disabled", !CascadeEnabledComponent.EnabledEffective(this));
                int j = index;
                builder.AddAttribute(208, "onclick", EventCallback.Factory.Create(this, () => HandleInputClick(j)));
                builder.AddEventStopPropagationAttribute(209, "onclick", true);
                builder.AddMultipleAttributes(250, this.AdditionalAttributes);
                builder.CloseElement();                 // input

                builder.OpenElement(300, "label");
                builder.AddAttribute(301, "class", "form-check-label");
                builder.AddAttribute(302, "for", inputId);
                if (ItemTemplateImpl != null)
                {
                    builder.AddContent(303, ItemTemplateImpl(item));
                }
                else
                {
                    builder.AddContent(304, SelectorHelpers.GetText(TextSelectorImpl, item));
                }
                builder.CloseElement();                 // label

                builder.CloseElement();                 // div
            }
        }
Exemple #5
0
        /// <inheritdoc/>
        protected override void BuildRenderInput(RenderTreeBuilder builder)
        {
            chipValue = null;

            RefreshState();

            bool enabledEffective = this.EnabledEffective;

            builder.OpenElement(0, "select");
            BuildRenderInput_AddCommonAttributes(builder, null);

            builder.AddAttribute(1000, "onchange", EventCallback.Factory.CreateBinder <string>(this, value => CurrentValueAsString = value, CurrentValueAsString));
            builder.AddEventStopPropagationAttribute(1001, "onclick", true);
            builder.AddElementReferenceCapture(1002, elementReferece => InputElement = elementReferece);

            if (itemsToRender != null)
            {
                if ((NullableEffective && enabledEffective) || (selectedItemIndex == -1))
                {
                    builder.OpenElement(2000, "option");
                    builder.AddAttribute(2001, "value", -1);
                    builder.AddAttribute(2002, "selected", selectedItemIndex == -1);
                    builder.AddContent(2003, NullTextImpl);
                    builder.CloseElement();
                }

                for (int i = 0; i < itemsToRender.Count; i++)
                {
                    var item = itemsToRender[i];
                    if (item != null)
                    {
                        bool selected = (i == selectedItemIndex);

                        if (enabledEffective || selected)                         /* when not enabled only selected item is rendered */
                        {
                            string text = SelectorHelpers.GetText(TextSelectorImpl, item);

                            builder.OpenElement(3000, "option");
                            builder.SetKey(i.ToString());
                            builder.AddAttribute(3001, "value", i.ToString());
                            builder.AddAttribute(3002, "selected", selected);
                            builder.AddContent(3003, text);
                            builder.CloseElement();

                            if (selected)
                            {
                                chipValue = text;
                            }
                        }
                    }
                }
            }
            else
            {
                if (!String.IsNullOrEmpty(NullDataTextImpl))
                {
                    builder.OpenElement(4000, "option");
                    builder.AddAttribute(4001, "selected", true);
                    builder.AddContent(4002, NullDataTextImpl);
                    builder.CloseElement();
                }
            }
            builder.CloseElement();
        }