Hello,
I try to create in my node red dashboard a drop zone where to drop a JSON. Then I want to run my flow from this input.
The code of the template node is the following:
<div id="dropZone"
style="width: 300px; height: 150px; border: 2px dashed #ccc; line-height: 150px; text-align: center;">
Drop your text here
</div>
<script>
const dropZone = document.getElementById('dropZone');
dropZone.addEventListener('dragover', (e) => {
e.preventDefault();
e.stopPropagation();
dropZone.style.borderColor = 'blue';
});
dropZone.addEventListener('dragleave', (e) => {
e.preventDefault();
e.stopPropagation();
dropZone.style.borderColor = '#ccc';
});
dropZone.addEventListener('drop', (e) => {
e.preventDefault();
e.stopPropagation();
dropZone.style.borderColor = '#ccc';
// Retrieve the dropped text
const text = e.dataTransfer.getData('text/plain');
if (text) {
// Send the text to Node-RED flow
if (typeof scope !== 'undefined' && scope.send) {
scope.send({ payload: text });
} else {
console.log('Dropped text:', text);
}
} else {
alert('No text data dropped');
}
});
</script>
and it gives this in the dashboard:
If I drop the JSON text in the "text input" it works well. But nothing from the template node.
Can someone help me?
Thanks