Opened

SelectList IsSelected validation is red with default value

ktraynor commented edited

I have code that looks like this, and then on OnInitializedAsync, I set _newFeature.ModuleId to an Id. If I don't have a Validator set, this seems to work fine, I get the correct value when I save. However, when I set Validator="ValidationRule.IsSelected" , then the input is red and I have to select a different item, then reselect the default to get it to turn green. Am I misusing this, or is this a bug?

<Validation Validator="ValidationRule.IsSelected">
		<Field Horizontal="true">
				<FieldLabel ColumnSize="ColumnSize.Is2">Module</FieldLabel>
					<FieldBody ColumnSize="ColumnSize.Is10">
						<Select @bind-SelectedValue="_newFeature.ModuleId" >
								@foreach (var module in _modules)
								{
									<SelectItem Value="@module.Id">@module.Name</SelectItem>
								}
						</Select>
				</FieldBody>
		</Field>
</Validation>
mladenmacanovic commented

This is by design. When select is populated it will not trigger onchange event. Only after the user chooses something it will be triggered.

My advice is to add a default empty option so that the user can see that some option is missing.

Example

<Select @bind-SelectedValue="_newFeature.ModuleId" >
	<SelectItem Value="0"></SelectItem>
	@foreach (var module in _modules)
	{
		<SelectItem Value="@module.Id">@module.Name</SelectItem>
	}
</Select>
Want to comment on this issue? Log in and write your comment.
Asignee
No assignee
Labels
No Labels