From 7332998e8945e91a28557ce0ebef72662456ace3 Mon Sep 17 00:00:00 2001 From: "Guillaume (gdi)" Date: Mon, 12 Jun 2023 09:40:10 +0000 Subject: [PATCH] [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 --- addons/website_forum/static/src/js/website_forum.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/website_forum/static/src/js/website_forum.js b/addons/website_forum/static/src/js/website_forum.js index afbe847d123..90ed83e0c1e 100644 --- a/addons/website_forum/static/src/js/website_forum.js +++ b/addons/website_forum/static/src/js/website_forum.js @@ -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 {