[FIX] website_forum: permit to post an image without text

In the website forum, we checked that the post content is not empty
before posting a post or an answer. Before this commit, it was just a
verification that the content is not an empty string.
Users are also able to post an image and we want to allow them to create
a post or an answer with only an image. This commit changes the
verification to check if the content is empty or if it only contains
images.

Steps to reproduce the issue resolved by this commit:
- Go to the website forum
- Create a new post
- Set a title
- Add an image as description
- Click on "Post Your Question"

=> The post is not created because the content is considered as empty.

task-2865782

X-original-commit: 048c6b779423ff34dd80f51e2a9202e16553a3ae
Part-of: odoo/odoo#124740
This commit is contained in:
Guillaume (gdi)
2023-06-13 08:44:18 +02:00
parent c9babef3c8
commit 7332998e89
@@ -181,7 +181,9 @@ publicWidget.registry.websiteForum = publicWidget.Widget.extend({
let $title = $form.find('input[name=post_name]');
let $textarea = $form.find('textarea[name=content]');
// It's not really in the textarea that the user write at first
let textareaContent = $form.find('.o_wysiwyg_textarea_wrapper').text().trim();
const fillableTextAreaEl = $form[0].querySelector(".o_wysiwyg_textarea_wrapper");
const isTextAreaFilled = fillableTextAreaEl &&
(fillableTextAreaEl.innerText.trim() || fillableTextAreaEl.querySelector("img"));
if ($title.length && $title[0].required) {
if ($title.val()) {
@@ -195,7 +197,7 @@ publicWidget.registry.websiteForum = publicWidget.Widget.extend({
// Because the textarea is hidden, we add the red or green border to its container
if ($textarea[0] && $textarea[0].required) {
let $textareaContainer = $form.find('.o_wysiwyg_textarea_wrapper');
if (!textareaContent.length) {
if (!isTextAreaFilled) {
$textareaContainer.addClass('border border-danger rounded-top');
validForm = false;
} else {