How to set src of video tag at dynamic?
Question
Hi @artf ,
Hi I have drag and drop video tag and button from blockmanager, On Clicking the button , I need to change the url to src. But not working, Please guide me.
editor.BlockManager.add("html/video", { label: `<div>
<img src="../../../Images/SiteBuilder/video.svg"/>
<div class="my-label-block">Video</div>
</div>`,
category: 'UI Controls',
tab: 'UI Controls',
id: 'UI Controls',
content: `<video id="video1" src="../../../Images/Jotun/Media21-1.m4v"id="TestVideo" controls type="video/mp4">`,
});
Button Event:
va url = "../../test.mp4";
$("#video1").attr('src', url);
Its not applied, Let me know the anyother way to set.Answers (3)
I think I have something like that made with a custom component. Maybe it helps
"use strict";
const videowithupload = (editor) => {
editor.DomComponents.addType("videowithupload", {
// isComponent: (el) => {
// console.debug(el);
// },
model: {
defaults: {
tagName: 'video',
autoplay: true,
loop: true,
muted: true,
controls: false,
poster: "poster.png",
src: "",
draggable: false,
removable: false,
copyable: false,
resizable: false,
stylable: [],
traits: []
},
init() {
console.debug("video - model - init");
},
updated(property, value) {
// console.debug(property);
// console.debug(value);
// console.debug(prevValue);
if (property === "src")
this.set("src", value);
}
},
view: {
events: {
dblclick: "onActive"
},
init() {
console.debug("video - view - init");
const { model } = this;
const props = [
'loop',
'autoplay',
'controls',
'color',
'rel',
'modestbranding',
'poster'
];
const events = props.map(p => `change:${p}`).join(' ');
this.listenTo(model, 'change:src', this.updateSrc);
this.listenTo(model, events, this.updateVideo);
},
onRender() {
console.debug("video - view - onRender");
this.updateVideo();
},
updateVideo(){
const { model, el } = this;
el.loop = model.get('loop');
el.autoplay = model.get('autoplay');
el.controls = model.get('controls');
el.poster = model.get('poster');
},
updateSrc() {
console.debug("video - view - updateSrc");
const { model, el } = this;
if (!el) return;
let src = model.get('src');
el.src = src;
},
onActive(e) {
console.debug("video - view - onActive");
editor.runCommand('open-assets', {
target: this.model,
types: ['videos'],
accept: 'video/*',
onSelect() {
console.debug("video - upload - onSelect")
editor.Modal.close();
editor.AssetManager.setTarget(null);
}
});
e.stopPropagation();
}
},
});
}
export default videowithupload;
If you need to update only the block content (eg. the change will be applied on new dragged blocks) you can change it in this way:
const block = editor.BlockManager.get('html/video');
block.set('content', '<video ...>')
if you need to change Components in the canvas, I'd recommend reading more in detail Components
,Thanks @artf and stf1981 for your response, Actually I drag and drop multiple videos with generated Random number to Id attribute. In this case How to update src specific selected video?
I gets failed to update src.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1722
[QUESTION] how to make my custom tag as selectable and editable inside of canvas ?
Hi, I try to change my custom tag of ion-item has div in view properties but It doesn't work for me as I expected. my custom Blocks is my c...
Issue #2177
How to create a block with HTML and CSS and javascript content.
Can somebody please show me a code example of how to create a block with javascript and css styles. The main problem is that the js code is...
Issue #2961
BUG: Components in custom modal isn't editable
Hello, I'm trying to add custom modal block to my project and I want to change content of this modal also with drag&drop. Here's code of my...
Issue #2596
[QUESTION] Add html, css and js to Block Manager
[QUESTION] Hi! I'm retrieving dynamic html,css and js codes from the database. How can I create Blocks with this? Currently, this is my cod...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.