Completed
Last Updated: 10 Mar 2023 13:28 by ADMIN
Release 4.1.0 (15/03/2023)
Desarrollo.BC
Created on: 06 May 2021 08:41
Category: Editor
Type: Bug Report
6
Cannot clear the editor content when placed in the form item template

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>

0 comments