Skip to content

Commit bd275b4

Browse files
committed
[FIX] html_editor, *: disable add button when video URL is empty
*=website Steps to reproduce: 1. Drop a video 2. Reopen the media dialog 3. Remove the URL 4. Confirm Issue: When the URL was removed and confirmed, an iframe without a valid source was saved, leading to a 404 error. Fix: When the video URL is cleared, VideoSelector component calls selectMedia with an empty object. MediaDialog did not previously handle this case, so the media selection was not cleared. Now we Update MediaDialog to treat an empty object as a clear-selection signal and disable the Add button accordingly. task-5190485 closes odoo#239668 X-original-commit: 4602d48 Signed-off-by: Francois Georis (fge) <fge@odoo.com> Signed-off-by: Dhruv Chauhan (chdh) <chdh@odoo.com>
1 parent ebf2025 commit bd275b4

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

addons/html_editor/static/src/main/media/media_dialog/media_dialog.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,11 @@ export class MediaDialog extends Component {
279279
}
280280

281281
selectMedia(media, tabId, multiSelect) {
282+
if (media && !Object.keys(media).length) {
283+
// Clear media selection when an empty object is passed
284+
this.selectedMedia[tabId] = [];
285+
return;
286+
}
282287
if (multiSelect) {
283288
const isMediaSelected = this.selectedMedia[tabId]
284289
.map(({ id }) => id)

addons/website/static/tests/tours/media_iframe_video.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,45 @@ registerWebsitePreviewTour(
3838
trigger: "a:contains('Videos')",
3939
run: "click",
4040
},
41+
{
42+
content: "Enter text in video link input to enable add button",
43+
trigger: "#o_video_text",
44+
run: "edit https://youtu.be/nbso3NVz3p8",
45+
},
46+
{
47+
content: "Wait for add button to be enabled",
48+
trigger: ".modal-footer button:contains('Add'):not([disabled])",
49+
run: () => {},
50+
},
51+
{
52+
content: "Remove video link",
53+
trigger: "#o_video_text",
54+
run() {
55+
const inputEl = this.anchor;
56+
inputEl.value = "";
57+
inputEl.dispatchEvent(new Event("input", { bubbles: true }));
58+
},
59+
},
60+
{
61+
content: "Video input field should not be in valid state",
62+
trigger: "#o_video_text:not(.is-valid)",
63+
run: () => {},
64+
},
65+
{
66+
content: "Check that the preview is not shown",
67+
trigger: ".media_iframe_video:not(:has(iframe))",
68+
run: () => {},
69+
},
70+
{
71+
content: "Check that the add button is disabled in footer",
72+
trigger: ".modal-footer",
73+
run: function () {
74+
const addButtonEl = this.anchor.querySelector(".btn.btn-primary");
75+
if (!addButtonEl.disabled) {
76+
console.error("Add button is not disabled.");
77+
}
78+
},
79+
},
4180
{
4281
content: "Enter video link",
4382
trigger: "#o_video_text",

0 commit comments

Comments
 (0)