valid port connections are not working

Hello,

after clicking on the check button, it always shows an alert message of "wrong connections" nothing else. Please refer to my code snippet attached "index4.html" & make changes accordingly.


Thanks
Rahul Kumar

Attachment: RRR__Copy_23e6b292.zip

1 Reply 1 reply marked as answer

AR Aravind Ravi Syncfusion Team December 15, 2020 01:07 PM UTC

Hi Rahul,  
 
On analyzing the provided code snippet you have added the randomID for the ports. So while checking the connections, it shows wrong connections. So if you want to check the connection means then do not add randomId for the port. We have modified a sample to remove the randomID for some ports. In the check connection function you have checked the port connection as port.Resistor_Port1, but it returns as undefined. Please check the port id as “Resistor_Port1” or ports[0]. Please refer to below code snippet and modified sample  
 
ports: [{  
//Do not add random ID at last of port name  
                            name: "Resistor_port1",  
                            offset: {  
                                x: 0,  
                                y: 0.5  
                            },  
                            shape: ej.datavisualization.Diagram.PortShapes.Circle,  
                            visibility: true,  
                            fillColor: "red",  
                            size: 12  
                        }, {  
                           name: "Resistor_port2",  
                            offset: {  
                                x: 1,  
                                y: 0.5  
                            },  
                            shape: ej.datavisualization.Diagram.PortShapes.Circle,  
                            visibility: true,  
                            fillColor: "red",  
                            size: 12  
                        }, ]  
 
function showAlert(event) {  
                for(var i = 0 ; i < diagram.model.connectors.length ; i++) {  
                var connector = diagram.model.connectors[i];  
                if (connector.sourcePort == "Resistor_port1" && connector.targetPort == "Resistor_port1")  
                    alert("Correct Connections");  
                else if (connector.sourcePort == "Resistor_port2" && connector.targetPort == "Resistor_port2")  
                    alert("Correct Connections");  
                else if (connector.sourcePort != "Resistor_port1" && connector.targetPort != "Resistor_port1")  
                    alert("Wrong Connections");  
                else if (connector.sourcePort != "Resistor_port2" && connector.targetPort != "Resistor_port2")  
                    alert("Wrong Connections");  
                else if (diagram.model.connectors.length <= 0 && diagram.model.connectors.length > 2)  
                    alert("Please use appropraite connections");  
                else  
                    alert("Wrong Connections");  
                }  
 
            }  
 
 
Similarly, in your sample you can remove the randomID for the ports and check connection for the connector as your need by using the connector sourcePort and targetPort properties.   
 
Regards  
Aravind Ravi 


Marked as answer
Loader.
Up arrow icon