I cannot clear the content area of the TelerikEditor when the component is placed in the Form Item Template.
<AdminEdit>
Below, you can find a workaround solution:
@using System.ComponentModel.DataAnnotations;
@using Telerik.Blazor.Components.Editor
<TelerikForm Model="@Model" OnSubmit="@OnSubmitHandler">
<FormValidation>
<DataAnnotationsValidator />
<ValidationSummary />
</FormValidation>
<FormItems>
<FormItem>
<Template>
<TelerikEditor @bind-Value="@Model.Name" @ref="@EditorRef" />
</Template>
</FormItem>
</FormItems>
</TelerikForm>
@code {
public SampleData Model { get; set; } = new SampleData();
public TelerikEditor EditorRef { get; set; }
private async Task OnSubmitHandler(EditContext editContext)
{
bool isFormValid = editContext.Validate();
if (isFormValid)
{
//some logic here
}
else
{
await EditorRef.ExecuteAsync(new HtmlCommandArgs("setHtml", "")); //workaround
//clear the content of the editor to let the user type anew
Model.Name = String.Empty;
}
}
public class SampleData
{
[Required]
[MinLength(30, ErrorMessage = "The content should be minimum 30 characters long.")]
public string Name { get; set; }
}
}
</AdminEdit>