How to make bootstrap 4 carousel work with grapesjs?
Question
I've successfully built a little drag and drop builder with grapesjs. Works great. The problem I'm facing is when dragging a bootstrap carousel inside the builder. The carousel works as expected on a regular page. But when inside the framework, only the first image shows up and I'm unable to use the controls to switch from one image to another. I've looked into the lory plugin but I'd love to be able to do this with bootstrap. Any grapesjs expert who can help?
See my builder here on Codepen : Example
To reproduce : Open Blocks. Then drag and drop one of the carousel inside the builder.
grapesjs
function customPlugin(editor){
//slide1
editor.BlockManager.add('slide1', {
category : 'Carousel',
label: '<h1><i class="far fa-play-circle fa-lg"></i></h1> Slides only',
content : '<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel"> <div class="carousel-inner"> <div class="carousel-item active"> <img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(35).jpg"> </div> <div class="carousel-item"> <img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(33).jpg"> </div> <div class="carousel-item"> <img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(31).jpg"> </div> </div> </div>'
});
//slide2
editor.BlockManager.add('slide2', {
category : 'Carousel',
label: '<h1><i class="far fa-play-circle fa-lg"></i></h1> Slides With controls',
content : '<div id="carouselExampleControls" class="carousel slide" data-ride="carousel"> <div class="carousel-inner"> <div class="carousel-item active"> <img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(45).jpg" alt="First slide"> </div> <div class="carousel-item"> <img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(46).jpg" alt="Second slide"> </div> <div class="carousel-item"> <img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(47).jpg" alt="Third slide"> </div> </div> <a onclick="prevSlide()" class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev"> <span onclick="prevSlide()" class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a onclick="nextSlide()" class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div>'
});
}
var editor = grapesjs.init({
container : '#gjs_container',
storageManager: {
type: 'remote',
autosave: true,// Store data automatically
autoload: true,// Autoload stored data on init
stepsBeforeSave: 1,
urlStore: 'queries/save_webpage.php',
urlLoad: 'queries/load_webpage.php',
// For custom parameters/headers on requests
params: { _some_token: '' },
headers: { Authorization: 'Basic' },
},
plugins: [
customPlugin
],
pluginsOpts: {},
canvas: {
styles: [
'https://use.fontawesome.com/releases/v5.8.2/css/all.css',
'https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap',
'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css',
'https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.19.1/css/mdb.min.css',
],
scripts: [
'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.4/umd/popper.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/js/bootstrap.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.19.1/js/mdb.min.js',
],
}
});
Answers (3)
if you get any solution please reply, as I'm searching for the same solution.
The slider call should be triggered once you drop a new block. Learn more about Components and Components with JS. Using only blocks is not enough for such functionality
@pranay2210 were you able to find a solution towards this
Related Questions and Answers
Continue research with similar issue discussions.
Issue #2129
[Question] how to append a button inside default modal and catch it's click event
I want a form inside a modal (using the default modal ), on click of the submit button make an ajax call. I have created a new component wh...
Issue #6271
BUG: Drag and drop of components doesn't work on latest Firefox
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Firefox 131.0 (64-bit) on Linux and Mac Re...
Issue #4480
BUG: Iframe on a block can't be edited
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Firefox v102.0.1 Reproducible demo link Th...
Issue #2473
Drag and drop issue in dragMode of translate
there is an issue am facing (seems offset issue) while trying and hold and drag the toolbar's move icon i have added bootstrap and columns...
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.