I have multiple select fields on my component and would like to add a custom @onchange-handler (like an onafterchange or something like that) in addition to the default @bind-behavior (value and @onchange).
This handler should only set a flag to indicate that the user can save, because this selection has changed a value of the parameter. For an input field, the @oninput can be used for this (see code below).
I don't want to overwrite the default @onchange but just add this to it. Is there a way I can add this or do I have to manually overwrite the @onchange for each select field on the component?
I tested @onselectionchange, @onselect and @onselectstart but these sadly weren't called.
// MyComponent.razor
<button disabled=@IsDisabled @onclick=DoSave>Save</button>
<input type="text" @bind=TestSample.TestInputValue @oninput=SetChanged />
@* How to call SetChanged after @onselect here? *@
<select @bind=TestSample.TestOptionValue>
<option value="A">A</option>
<option value="B">B</option>
</select>
@code {
[Parameter]
public TestSample TestSample { get; set; }
private bool IsDisabled;
protected override void OnInitialized()
{
base.OnInitialized();
IsDisabled = true;
}
private void SetChanged()
{
IsDisabled = false;
}
private void DoSave()
{
// Do some Task...
}
}
// TestSample.cs
public class TestSample
{
public string TestOptionValue { get; set; }
public string TestInputValue { get; set; }
}