-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Description
Is there an existing issue for this?
- I have searched the existing issuesTo pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Describe the bug
When binding a complex model to one of blazors built in input components (inherits InputBase<T>
) you can run into an issue where the input component is no longer holding a reference to the correct model, and therefore validation does not behave as expected. Sometimes the validation message does not display. 100% of the time the FieldCssClass
will not be set correctly.
Expected Behavior
Validation messages and css classes should still be applied when the underlying model for a input component changes.
Steps To Reproduce
Consider a model like this
public class ComplexModel
{
public string Property1 { get; set; }
public ChildModel Child { get; set; } = new();
}
public class ChildModel
{
[Required]
public string? Name { get; set; }
public int Id { get; set; }
}
and a blazor component like this
<EditForm OnSubmit="SubmitModel" Model="ComplexModel">
<p>Select a child</p>
<ul>
@foreach(var child in ChildOptions)
{
<li><button type="button" @onclick="() => SelectChild(child)">Child @child.Id</button></li>
}
</ul>
<label for="ChildName">Child Name</label>
<InputText @bind-Value="Model.Child.Name"
id="ChildName" />
<ValidationMessage For="Model.Child.Name" />
<button type="submit">Submit</button>
</EditForm>
@code {
private ComplexModel Model { get; set; } = new();
private ChildModel[] ChildOptions { get; } = [
new ChildModel() { Id = 1; }
new ChildModel() { Id = 2; }
new ChildModel() { Id = 3; }
];
void SelectChild(ChildModel child)
{
Model.Child = child;
}
void SubmitModel()
{
// Do things
}
}
After selecting one of the children the validation message for the required Name
property may or may not display. 100% of the times I tested this the invalid
class was not applied to the input.
Exceptions (if any)
No response
.NET Version
8 (assuming 9 is affected a well).
Anything else?
No response
Activity
bonsall commentedon Jun 24, 2025
I have provided example code in the "Steps To Reproduce" section. Is this not good enough?
javiercn commentedon Jun 24, 2025
@bonsall thanks for contacting us.
We require a project as a public github repository that reproduce the issue as well as detailed steps on how to reliably reproduce the issue.
Otherwise, there is a chance that there is an important detail that is missing from the repro (even if not evident) or that we make a mistake in reproducing the issue, which complicates the diagnosis of any potential problem.
dotnet-policy-service commentedon Jun 24, 2025
Hi @@bonsall. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
dotnet-policy-service commentedon Jun 30, 2025
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.
See our Issue Management Policies for more information.