This is for a .NET 8 blazor webapp.
I have a grid that has an Editor Template as follows:
<EditorTemplate>
@{
CurrentlyEditedItemSupplier = (context as ItemSupplier)!;
<HiSS.Body.Components.Custom.ItemSelector Items="@Items" CurrentItemSupplier="@CurrentlyEditedItemSupplier" Categories="@Categories" />
<TelerikValidationTooltip For="@(() => CurrentlyEditedItemSupplier.ItemId)"
TargetSelector="#Item-field"
Position="@TooltipPosition.Bottom">
</TelerikValidationTooltip>
}
It contains a custom control (ItemSelector) that has 3 comboboxes. The first one is a category selector that filters item records to a smaller subset, the other two are linked to the items and show different fields from them, allowing the user to choose from either an id number or description. The parent grid is bound to an object of type ItemSupplier. This does not contain a Category id that is bound to in the first combobox. The other two are bound to an item id that is in the object.
<TelerikComboBox Id="Category-field" Data="@Categories" @bind-Value="@CurrentCategoryId" TextField="@nameof(Category.Name)" ValueField="@nameof(Category.Id)" OnChange="@FilterItems"
Width="39%">
<ComboBoxSettings>
<ComboBoxPopupSettings Class="dropdownsize;" />
</ComboBoxSettings>
</TelerikComboBox>
<TelerikComboBox id="Item-Desc" Data="@FilteredItems" @bind-Value="@CurrentItemSupplier!.ItemId" TextField="@nameof(Item.Description)" ValueField="@nameof(Item.Id)"
Width="39%">
<ComboBoxSettings>
<ComboBoxPopupSettings Class="dropdownsize;" />
</ComboBoxSettings>
</TelerikComboBox>
<TelerikValidationTooltip For="@(() => CurrentItemSupplier.ItemId)"
TargetSelector="#Item-Desc"
Position="@TooltipPosition.Bottom">
</TelerikValidationTooltip>
<TelerikComboBox id="Item-ItemNo" Data="@FilteredItems" @bind-Value="@CurrentItemSupplier!.ItemId" TextField="@nameof(Item.ItemNo)" ValueField="@nameof(Item.Id)"
Width="20%">
<ComboBoxSettings>
<ComboBoxPopupSettings Class="dropdownsize;" />
</ComboBoxSettings>
</TelerikComboBox>
<TelerikValidationTooltip For="@(() => CurrentItemSupplier.ItemId)"
TargetSelector="#Item-ItemNo"
Position="@TooltipPosition.Bottom">
</TelerikValidationTooltip>
The Category is used purely for filtering the items to give a smaller list to the user. Unfortunately, validation doesn’t like it being there as it doesn’t exist on the validation model. If I comment out the Category combobox everything works fine, but the item list is too big. How do I get the validation to ignore the Category combobox in the custom control?
Turned out to be pretty simple – all I have to do is wrap the offending control in its own Editform:
<EditForm Model="@dummymodel">
<TelerikComboBox Id="Category-field" Data="@Categories" @bind-Value="@CurrentCategoryId" TextField="@nameof(Category.Name)" ValueField="@nameof(Category.Id)" OnChange="@FilterItems" >
<ComboBoxSettings>
<ComboBoxPopupSettings Class="dropdownsize;" />
</ComboBoxSettings>
</TelerikComboBox>
</EditForm>
with the dummymodel defined as:
private object dummymodel = new object();
and it works fine…