You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
mmuller88
changed the title
MatSelect IsModified from EditContext - With Workaround
MatSelect IsModified() from EditContext - With Workaround
Aug 17, 2021
I am not a big expert in Blazor and MatBlazor, but I tried to reproduce the issue and try to google some examples (about EditContext in general without linking to MatBlazor).
I found another workaround (or maybe it is expected behavior for Blazor at all)
<EditForm EditContext="_editContext">
<MatSelect Label="Parks" @bind-Value="_parkSelectorModel.ParkId" TValue="int">
@foreach (var park in _parks)
{
<MatOption Value="@park.Id">@park.Name</MatOption>
}
</MatSelect>
<MatButton Disabled="!_editContext.IsModified()">Save</MatButton>
</EditForm>
@code {
EditContext _editContext;
readonly ParkSelectorModel _parkSelectorModel = new ParkSelectorModel();
readonly Park[] _parks = new Park[]
{
new Park()
{
Id = 1,
Name = "Park 1"
},
new Park()
{
Id = 2,
Name = "Park 2"
}
};
protected override void OnInitialized()
{
_editContext = new EditContext(_parkSelectorModel);
_editContext.OnFieldChanged += (sender, args) =>
{
StateHasChanged();
};
}
public class Park
{
public int Id { get; set; }
public string Name { get; set; }
}
public class ParkSelectorModel
{
public int ParkId { get; set; }
}
}
Describe the bug
The MatSelect together with the EditContext IsModified() only triggers on the second select.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Save button is not disabled
Actual behaviour
Save button is disabled
Workaround
Use onclick to make IsModified() working for the first select.
The text was updated successfully, but these errors were encountered: