Megabit / Blazorise

Blazorise is a component library built on top of Blazor with support for CSS frameworks like Bootstrap, Tailwind, Bulma, AntDesign, and Material.
https://blazorise.com/
Other
3.2k stars 523 forks source link

Validation for RichTextBox #1792

Open ivancavlek opened 3 years ago

ivancavlek commented 3 years ago

Hi!

Is it possible to validate RichTextBoxes and how? If not, will this feature be added?

Regards, Ivan

stsrki commented 3 years ago

Not at the moment but it could be added sometime in the future.

stsrki commented 1 year ago

The built-in validation would require significant API changes to the RTE. We will move this feature to v2.0.

Until then, as a workaround the validation can be done as follows:

<RichTextEdit @ref="richTextEditRef"
                ConfigureQuillJsMethod="blazoriseDemo.configureQuillJs"
                ContentChanged="@OnContentChanged"
                Border="@( string.IsNullOrWhiteSpace( contentAsText ) ? Border.Danger : null)">
      ...
  </RichTextEdit>
  @if ( string.IsNullOrWhiteSpace( contentAsText ) )
  {
      <Paragraph TextColor="TextColor.Danger">Text is empty</Paragraph>
  }
  else
  {
      <Paragraph TextColor="TextColor.Success">Text is valid</Paragraph>
  }
@code{
    private string contentAsText;

    public async Task OnContentChanged()
    {
        contentAsText = await richTextEditRef.GetTextAsync();
    }
}