PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, October 28, 2022

[FIXED] What is the best way to check if the Rich Text Editor Content is empty in Vaadin 14?

 October 28, 2022     is-empty, rich-text-editor, vaadin, vaadin14     No comments   

Issue

I want to check if the Rich Text Editor is empty before proceeding a action. But the .isEmpty() method only works if no format button is clicked. So for example if you just press the H1 format button inside the editor without writing anything the .getValue() method returns:

[{"attributes":{"header":1},"insert":"\n"}]

And because of this the .isEmpty() method doesn't work properly in this case. So I want to check if there is any text or a image inside the editor.

Update: So the closest I can get is using this:

private boolean isEditorEmpty(String value) { //value = RichTextEditor.getHtmlValue()
    if (value.replaceAll("<[^>]*>", "").strip().length() < 1)
        return true;
    return false;
}

But I am not able to exclude pictures, because after adding a picture to the RichTextEditor the .getHtmlValue() method always returns an empty string.

Hope someone can help me


Solution

It works using this method to check if the editor is empty:

private boolean isEditorEmpty(String value) { //value = RichTextEditor.getHtmlValue()
   if (value == null || !value.contains("<img") && value.replaceAll("<[^>]*>", "").strip().length() < 1)
        return true;
    return false;
}


Answered By - Lukas
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing