Anchor no longer follows endpoint after Anchor ID is modified following creation - JSPlumb

I am currently developing an editor that involves placing shapes on a canvas and assigning IDs to them. When a shape is placed, endpoints are automatically created and attached to the shape using its ID as an anchor.

   //Function responsible for adding endpoints to shapes.

   var _addEndpoints = function (sourceAnchors, targetAnchors, id) {
   
    for (var i = 0; i < sourceAnchors.length; i++) {
        var sourceUUID = sourceAnchors[i];
 
        epp = jsPlumbInstance.addEndpoint(id, sourceEndpoint, {
            anchor: sourceAnchors[i], uuid: sourceUUID
        });
        sourcepointList.push([id , epp]);
        epp = null;
    }
    for (var j = 0; j < targetAnchors.length; j++) {
        var targetUUID = targetAnchors[j];
        epp = jsPlumbInstance.addEndpoint(id, targetEndpoint, {
            anchor: targetAnchors[j], uuid: targetUUID
        });
        
        endpointList.push([id, epp]);
        epp = null;
    }

};

function drawElement(element, canvasId, id) {
    $(canvasId).append(element);
    _addEndpoints(properties[0].startpoints, properties[0].endpoints, id);
    jsPlumbInstance.draggable(jsPlumbInstance.getSelector(".jtk-node"), {
        grid: [20, 20]
    });         
  }

The current setup functions well with the endpoints moving along with the shape when dragged. However, I would like to implement a feature where the ID of a shape can be changed by clicking on it. Upon changing the ID, the endpoints no longer move with the shape, though they still remain draggable independently. My attempted solution involved updating the ID in the endpoints by modifying the anchor and element attributes.

  //My attempted solution
  jsPlumbInstance.selectEndpoints().each(function(endpoint) {
      endpoint.setElement(anchor); 
      endpoint.setAnchor(x, y, newID);  
  });

Unfortunately, this approach led to an error message:

jsPlumb function failed : TypeError: Cannot read property 'el' of undefined

Upon inspecting the properties of the endpoints, I found several instances where the old ID value was still present. I am unsure how to update all these properties simultaneously. Any assistance on resolving this issue would be greatly appreciated.

Answer №1

After some troubleshooting, I discovered a simple fix that did the job. Instead of my initial approach, the solution lies in executing the following:

jsPlumbInstance.setId(oldID, ID);

By utilizing this code snippet, JSPlumb is instructed to automatically update the ID across all relevant components, streamlining the process and eliminating the need for manual adjustments.

Answer №2

For those using version 4.x, it's important to note that jsPlumb no longer relies on the DOM id internally, eliminating any potential issues in this newer version.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Morgan middleware in Express.js specifically targeting unsuccessful requests for logging purposes

Currently, I am facing an issue with my middleware setup in Express.js while using Morgan. The problem arises because Morgan is only logging requests that return error code 302 (redirected), which happens when my middleware encounters an error and redirect ...

If the value is null, pass it as is; if it is not null, convert it to a date using the

I am currently facing an issue regarding passing a date value into the rrule plugin of a fullCalendar. Here is the snippet of code in question: Endate = null; rrule: { freq: "Daily", interval: 1, dtstart: StartDate.toDate ...

Assigning a value to a variable from a method in Vue: a step-by-step guide

I'm having trouble assigning values from a method to variables in HTML. Here's what I have in my code: <b-card-text>X position {{xpos}}</b-card-text> <b-card-text>Y position {{ypos}}</b-card-text> I would like to assign v ...

Refreshing an external file in Node.js at regular intervals

Seeking guidance on loading external files in node. I'm currently working with an external JSON file that houses some configuration settings, and this file gets updated by an outside process every 10 minutes. How can I automate the reloading of this ...

Tips for displaying HTML5 validation messages when the input is changed

I am working on a form where I prefer not to submit it directly, as I am making an AJAX call instead. However, I still want the HTML5 validation messages to show up when an input field is left empty. I have managed to display the validation message when a ...

Axios failing to transmit cookie information, despite setting withCredentials to true

Exploring the capabilities of React and Express to handle requests while including cookies. The communication between client-side and server-side is successful, however, the cookies are not being transmitted. On the client-side: import axios from 'axi ...

An error occurred when trying to set a cookie using Set-Cookie in a react application

Currently, I am immersed in a small project that involves user authentication via email and password before gaining access to their individual profiles. The backend operates on cookies which are established once the correct email and password combination i ...

Is there a live password verification tool available?

Currently, I am conducting some initial research for my school's IT department as a student employee. The students at our institution are required to change their passwords every six months, but many of them struggle with the various password regulati ...

What is the way to retrieve an array property in a typescript interface?

Imagine a scenario with three interfaces structured as follows: registration-pivot.ts export interface RegistrationPivot { THead: RegistrationPivotRow; TBody: RegistrationPivotRow[]; } registration-pivot-row.ts export interface RegistrationPivotR ...

Executing JavaScript code in the Selenium IDE

I'm having trouble figuring out how to execute JavaScript within the Selenium IDE. The objective is to enter text into an input field, with a backend setup that verifies the current time in the input field for testing purposes: Here's the input f ...

Save documents in Firebase storage

Currently in the process of developing a web application using Firebase and Angularjs as my frontend tools. Curious to know whether it's feasible to store various file types within the Firebase DB. Could you shed some light on any potential limitatio ...

Why my attempts to alter numerous CSS elements using JQuery are failing?

Here's the code snippet I'm working with: var showThis = $(this).attr('id'); // div0, div1, div2 etc. $('#' + showThis).attr('style', 'background-color: #063 !important, height: 520px'); I am trying to mo ...

Manipulating links using JQuery: avoiding the binding of new links

I need to update a website with 50 pages that currently doesn't use ajax, making it cumbersome to make edits since changes have to be made on all 50 pages individually. After removing duplicate HTML from all 50 pages, I'm facing some issues: fu ...

Tips for implementing HTML5 validation followed by automatic redirection to a different page

I'm new to web development and struggling with how to make a button both validate inputs and redirect to another page. Using the onclick = "" function, I can validate inputs like emails and telephone numbers, but I'm having trouble making it so t ...

Is the state of the React.js component empty?

HTML: <!-- index.html --> <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>React Tutorial</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.6/react.js"></script> ...

Updating a specific row in a multiple row form can be achieved when the input field names match in a column

My task involves working with a report that generates a form in input mode. This form contains multiple rows of data, each row consisting of a button and an input field. The input field name remains consistent across all rows for easier processing by the C ...

Setting up a basic testcafe configuration with ES modules

Unique Title When it comes to using ES modules with Testcafe, the documentation may not provide clear instructions on configuring global hooks. There seems to be limited options for configuring Testcafe globally, such as using .json or CommonJS. In my pr ...

"Exploring the interactivity of touch events on JavaScript

Hi there, I'm currently facing an issue with the touch events on my canvas. While the mouse events are functioning correctly and drawing as expected, incorporating touch events seems to be causing a problem. When I touch the canvas, the output remains ...

Dealing with 'ECONNREFUSED' error in React using the Fetch API

In my React code, I am interacting with a third party API. The issue arises when the Avaya One-X client is not running on the target PC, resulting in an "Error connection refused" message being logged continuously in the console due to the code running eve ...

How is it possible that the SetTimeout code continues to run even after calling clearTimeout

I have this code snippet within my react component: //some code var timeout = null; //global variable //some more code useEffect(() => { if(...some condition) { console.log('test1'); timeout = setTimeout(() => { ...