This topic is locked

Drag and Drop

12/24/2025 09:49:02
PHPRunner General questions
M
MikeUk author

Has anyone every tried working with JS drag and drop?

I was thinking, that this would offer some great functionality that could speed up data entry, FOr example, an dashboad showing a list of orders and the user can click on one of the items in a grid, and drag it to an area on the form and it creates a pickup request for the courier.
Or I can think of several other uses for such fuctionality.

https://www.javascripttutorial.net/web-apis/javascript-drag-and-drop/

I was thinking along the lines of an Ajax evernt on the row click could capture the ID field of the record and store it in a $ SESSION [] then on-drop another ajax script runs to do any testing, either in JS or PHP and affer a cinfirmation, completes the update request.
I might do some experiments over the break, or get drunk, we'll see :)

ChatGPT 12/24/2025

Yes, using JavaScript's drag-and-drop functionality in a PHPRunner application can indeed enhance user experience and improve data entry efficiency. The concept you mentioned—dragging items from a grid to create a pickup request—is a practical application of this feature.

Here's a high-level overview of how you could implement this in PHPRunner:

  1. Set Up the Grid: Create a grid that displays the list of orders. Each row should be draggable. You can use the HTML5 drag-and-drop API to make the rows draggable.


  2. Implement Drag-and-Drop:

    • Use the draggable attribute on the table rows (<tr>).
    • Implement dragstart and dragend events to manage the drag operation.
    • Create a drop zone on your form where users can drop the dragged items.


  3. Capture the Data:

    • In the dragstart event, store the order ID (or any relevant data) in the dataTransfer object.
    • In the drop zone, handle the drop event to retrieve this data and perform any necessary validation.


  4. Use AJAX for Server-Side Processing:

    • After the drop event, you can trigger an AJAX call to send the order ID to your PHP script. This script can check for any conditions (e.g., if the order is eligible for pickup) and then create a pickup request if all checks pass.
    • Update the session variable or database as needed based on the result of the AJAX call.


  5. User Feedback: Provide feedback to the user, such as a confirmation message or visual indication that the drop was successful or failed.



Here’s a simple example of how this might look in JavaScript:

// Make table rows draggable
const rows = document.querySelectorAll('tr');
rows.forEach(row => {
row.setAttribute('draggable', true);

row.addEventListener('dragstart', (e) => {
e.dataTransfer.setData('text/plain', row.dataset.id); // Assume ID is stored in a data attribute
});
});

// Drop zone
const dropZone = document.getElementById('drop-zone');
dropZone.addEventListener('dragover', (e) => {
e.preventDefault(); // Necessary to allow dropping
});

dropZone.addEventListener('drop', (e) => {
e.preventDefault();
const orderId = e.dataTransfer.getData('text/plain');

// Perform AJAX call to create pickup request
fetch('createPickupRequest.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ orderId: orderId })
})
.then(response => response.json())
.then(data => {
// Handle response
if (data.success) {
alert('Pickup request created successfully!');
} else {
alert('Failed to create pickup request.');
}
});
});

Considerations:

  • Cross-Browser Compatibility: Ensure that your drag-and-drop implementation works well across different browsers.
  • Accessibility: Make sure to provide alternative methods for users who may have difficulties with drag-and-drop.
  • Data Validation: Always validate data on the server side, even if you do client-side checks.

Experimenting:

It sounds like you have a great plan for experimenting over the break! Try small prototypes first to see how the drag-and-drop functionality can work with your existing grid and forms. Good luck, and enjoy your experiments!

Sergey Kornilov admin 12/24/2025

We had this exact topic discussed in one of our DevClub webinars: https://xlinesoft.com/devclub

img alt