Once again, why would you do that? You need to initialize the cropper script once the data is loaded on your page.
You are currently trying to initialize it on document ready, which is quite too early, as the data is not loaded yet:
$(document).ready(function() {
const image = document.getElementById('image');
cropper = new Cropper(image, {
strict: true,
modal: false,
background: false,
minCanvasWidth: 569,
minCanvasHeight: 569,
minCropBoxWidth: 50,
minCropBoxHeight: 50,
scalable: false,
center: true,
guides: true,
zoomable: false,
zoomOnTouch: false,
zoomOnWheel: false,
crop(event) {
document.getElementById('left').value = event.detail.x;
document.getElementById('top').value = event.detail.y;
document.getElementById('width').value = event.detail.width;
document.getElementById('height').value = event.detail.height;
},
});
image.addEventListener('ready', function() {
if (this.cropper === cropper) {
cropper.setCropBoxData({
left: 200,
top: 200,
width: 300,
height: 300
})
}
// > true
});
})
Change this to:
function cropper_init() {
const image = document.getElementById('image');
cropper = new Cropper(image, {
strict: true,
modal: false,
background: false,
minCanvasWidth: 569,
minCanvasHeight: 569,
minCropBoxWidth: 50,
minCropBoxHeight: 50,
scalable: false,
center: true,
guides: true,
zoomable: false,
zoomOnTouch: false,
zoomOnWheel: false,
crop(event) {
document.getElementById('left').value = event.detail.x;
document.getElementById('top').value = event.detail.y;
document.getElementById('width').value = event.detail.width;
document.getElementById('height').value = event.detail.height;
}
});
image.addEventListener('ready', function() {
if (this.cropper === cropper) {
cropper.setCropBoxData({
left: 200,
top: 200,
width: 300,
height: 300
})
}
// > true
});
}
and call the cropper_init()
function on sc_list_prod_details
server action > static events > done?