// Would like to use <inheritdoc/> however DocFX cannot resolve to references outside Material.Blazor protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); MBItemValidation appliedItemValidation = CascadingDefaults.AppliedItemValidation(ItemValidation); ForceShouldRenderToTrue = true; bool hasValue; (hasValue, ComponentValue) = ValidateItemList(Items, appliedItemValidation); ConditionalCssClasses.AddIf("mb-mdc-radio-group-vertical", () => Vertical); }
// Would like to use <inheritdoc/> however DocFX cannot resolve to references outside Material.Blazor protected override void OnInitialized() { base.OnInitialized(); MBItemValidation appliedItemValidation = CascadingDefaults.AppliedItemValidation(ItemValidation); ForceShouldRenderToTrue = true; bool hasValue; (hasValue, ComponentValue) = ValidateItemList(Items, appliedItemValidation); ClassMapperInstance.AddIf("mb-mdc-radio-group-vertical", () => Vertical); }
// Would like to use <inheritdoc/> however DocFX cannot resolve to references outside Material.Blazor protected override void OnInitialized() { base.OnInitialized(); ItemArray = Items.ToArray(); MBItemValidation appliedItemValidation = CascadingDefaults.AppliedItemValidation(ItemValidation); ForceShouldRenderToTrue = true; ReportingValue = ValidateItemList(ItemArray, appliedItemValidation); ClassMapper.AddIf("mb-mdc-radio-group-vertical", () => Vertical); }
// This method was added in the interest of DRY and is used by MBSelect & MBRadioButtonGroup /// <summary> /// Validates the item list against the validation specification. /// </summary> /// <param name="items">The item list</param> /// <param name="appliedItemValidation">Specification of the required validation <see cref="MBItemValidation"/></param> /// <returns>The item in the list matching <see cref="InputComponentFoundation{T}._cachedValue"/></returns> /// <exception cref="ArgumentException"/> public T ValidateItemList(IEnumerable <MBListElement <T> > items, MBItemValidation appliedItemValidation) { var componentName = Utilities.GetTypeName(GetType()); if (items.Count() == 0) { throw new ArgumentException(componentName + " requires a non-empty Items parameter."); } if (items.GroupBy(i => i.SelectedValue).Where(g => g.Count() > 1).Count() > 0) { throw new ArgumentException(componentName + " has multiple enties in the List with the same SelectedValue"); } if (items.Where(i => object.Equals(i.SelectedValue, Value)).Count() == 0) { switch (appliedItemValidation) { case MBItemValidation.DefaultToFirst: var firstOrDefault = items.FirstOrDefault().SelectedValue; return(firstOrDefault); case MBItemValidation.Exception: string itemList = "{ "; string prepend = ""; foreach (var item in items) { itemList += $"{prepend} '{item.SelectedValue}'"; prepend = ","; } itemList += " }"; throw new ArgumentException(componentName + $" cannot select item with data value of '{Value?.ToString()}' from {itemList}"); case MBItemValidation.NoSelection: return(default); } } return(Value); }
// This method was added in the interest of DRY and is used by MBSelect & MBRadioButtonGroup /// <summary> /// Validates the item list against the validation specification. /// </summary> /// <param name="items">The item list</param> /// <param name="appliedItemValidation">Specification of the required validation <see cref="MBItemValidation"/></param> /// <returns>The an indicator of whether an item was found and the item in the list matching <see cref="InputComponent{T}._cachedValue"/> or default if not found.</returns> /// <exception cref="ArgumentException"/> public (bool hasValue, T value) ValidateItemList(IEnumerable <MBSelectElement <T> > items, MBItemValidation appliedItemValidation) { var componentName = Utilities.GetTypeName(GetType()); if (!items.Any()) { throw new ArgumentException(componentName + " requires a non-empty Items parameter."); } if (items.GroupBy(i => i.SelectedValue).Any(g => g.Count() > 1)) { throw new ArgumentException(componentName + " has multiple enties in the List with the same SelectedValue"); } if (!items.Any(i => Equals(i.SelectedValue, Value))) { switch (appliedItemValidation) { case MBItemValidation.DefaultToFirst: var defaultValue = items.FirstOrDefault().SelectedValue; _ = ValueChanged.InvokeAsync(defaultValue); AllowNextRender = true; return(true, defaultValue); case MBItemValidation.Exception: var itemList = "{ "; var prepend = ""; foreach (var item in items) { itemList += $"{prepend} '{item.SelectedValue}'"; prepend = ","; } itemList += " }"; throw new ArgumentException(componentName + $" cannot select item with data value of '{Value?.ToString()}' from {itemList}"); case MBItemValidation.NoSelection: _ = ValueChanged.InvokeAsync(default); AllowNextRender = true; return(false, default); } } return(true, Value); }