I am stuck with a problem that I just can't seem to solve:
I have built a TelerikForm with a Submit button. The requirement is to change the enabled status of this button depending on whether the form has been modified or not.
So the basic code is :
<TelerikForm @ref="@FormRef"
Model="@EntityModel"
OnSubmit="@OnSubmitHandler"
>
<FormValidation>
<DataAnnotationsValidator />
</FormValidation>
<FormItems>
<CascadingValue Name="TheForm" Value="@FormRef">
@foreach (var form_item in FormItemCollection)
{
<DynamicComponent Type="@form_item.ComponentType" Parameters="@form_item.Parameters" />
}
</CascadingValue>
</FormItems>
<FormButtons>
<TelerikButton
ButtonType="@ButtonType.Submit"
Enabled="@SaveEnabled"
ThemeColor="primary">Speichern</TelerikButton>
</FormButtons>
</TelerikForm>The ButtonShould be changed on the EditContext.IsModified() state.
So I tried:
protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
{
FormRef.EditContext.OnFieldChanged += EditContext_OnFieldChanged;
}
base.OnAfterRender(firstRender);
}
private void EditContext_OnFieldChanged(object sender, FieldChangedEventArgs e)
{
SaveEnabled = true;
StateHasChanged();
}
I can't find any solution to change the State of the Button without StateHasChanged. The enabled attribute is not a bound value, so the state does not change.
So how to solve this troubles?
