Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Drag and Drop Without Writing JavaScript with WFC + Online Demo

Drag and Drop interactions are usually implemented with client-side JavaScript. Developers typically need to listen for pointer events, track the dragged element, prevent default browser behavior, update CSS classes, and finally move or remove the element. With WebForms Core (WFC) , the same interaction can be implemented by defining events and commands on the server. No custom JavaScript event…

Developing Drag and Drop interactions typically involves client-side JavaScript. Developers must handle pointer events, track the dragged element, prevent default browser actions, modify CSS classes, and manipulate the element's position. However, WebForms Core (WFC) simplifies this process dramatically. With WFC, the same Drag and Drop functionality can be achieved by defining events and commands on the server.

No custom JavaScript code is needed to implement this interaction. The following example demonstrates this concept using Node.js and Express. It is suggested to examine the accompanying drag-and-drop demo prior to reviewing the code. The demo is hosted at webforms-core.github.io.

The web page features two zones: a `dragZone` containing draggable elements and a `dropZone` serving as the destination area. When an item is dragged using a mouse, it can seamlessly transition between the two zones. For touch devices, where traditional HTML Drag and Drop may not be as effective, a tap can be employed to move an item between the zones.

The provided code snippet utilizes the Express framework in Node.js to set up the server. It imports the necessary modules from `express` and `WebForms`. An instance of `express` is created, and the static directory `public` is configured to serve static files. The application routes the root URL to display the web form.

To implement the Drag and Drop functionality, the `WebForms` object is configured with various event handlers. On the `dragZone`, event handlers are set for `dragStart`, `dragEnd`, `dragOver`, `dragLeave`, and `drop` events. These handlers are defined using the `setCommentEvent` method, mapping the respective event names to the corresponding functions. Additionally, event handlers for touch devices are also defined using `OnTouchStart` for the `dragZone`.

The `startIndex` method is invoked to initiate the Drag and Drop process. Various CSS classes are inserted or deleted based on the event type using methods like `insertClass` and `deleteClass`. For instance, when `dragOver` occurs, the `dropZone` receives the `highlight` class to visually indicate the drop target. Conversely, when `dragLeave` takes place, the `highlight` class is removed from the `dropZone`.

To complete the Drag and Drop operation, the `drop` event handler is triggered. It uses `Fetch.save` to remove the dragged element from the `dragZone`. Simultaneously, `Fetch.save` is employed on the `dropZone` to add the moved element. Finally, `startIndex` is called once more to finalize the Drag and Drop interaction on the `dropZone`, and the `addText` method is used to display the moved item.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

OpenTofu 1.13: What's New and What Terraform Still Doesn't Have

Originally published on DevToolHub . OpenTofu 1.13.0 shipped on September 30, 2026. Officially-supported Windows on ARM64, a set of new functions, and upgrades to the state-encryption system it…

  • OpenTofu 1.13.0 launched on September 30, 2026
  • Adds Windows ARM64 support, convert function, assume prefix functions
  • Plan files now include provider schemas

How to Build a Zero-Cost Automated Store Using a Telegram Bot

Many developers overcomplicate e-commerce. They look at Stripe integrations, massive Shopify storefronts, and server infrastructure.

  • Zero-cost automated store built with Telegram bot
  • Python-telegram-bot library handles core functionality
  • Server setup using $5/mo DigitalOcean Droplet

JavaScript SEO: How to Make Sure Google Can Render, Crawl, and Index Your Site

Modern websites rely heavily on JavaScript frameworks such as React, Vue, and Angular. They create fast, app-like experiences, but they can also hide content from search engines if built carelessly.

  • Google processes JavaScript pages in three stages: crawling, rendering, and indexing
  • Server-side rendering sends full HTML to crawlers and users immediately
  • Best practices include serving critical content in initial HTML and using real anchor tags

More from Thursday 8 October →