Hi Roman,
Even after removing the element from DOM, I am able to add child elements to it? How is it possible? My application is working wrong if its like this.
pointerclick: function (evt, x, y) {
var view = paper.findViewByModel(this.model);
var currentParentId = this.model.attributes.parent;
currentParentCell = graph.getCell(currentParentId);
shapeCount = currentParentCell.attributes.count;
var embeddedCells = currentParentCell.getEmbeddedCells();
if (evt.target.parentNode.getAttribute('class') === 'element-tool-remove' && embeddedCells.length === 1)
{
this.model.remove();
currentParentCell.remove(); // removing the element
}
}
Here I am adding new elements which should not add if the parent element is removed from DOM:
$('.modeler_add_button').on("click", function (event)
{
if ($.trim($('#columnValue_1').val()).length)
{
try
{
if (currentParentCell.attributes.count === shapeCount)
{
count = shapeCount;
}
}
catch (err)
{
console.log(err);
}
var columnValue_1 = $('#columnValue_1').val();
var hasValues = checkInputLength(columnValue_1);
if (hasValues)
{
var columnValue_1 = columnValue_1;
var textWidth = $('#columnValue_1').textWidth();
//set Toggle to visible before adding new column
setToggleVisible(currentParentCell.id, currentParentCell.getEmbeddedCells());
//Function call to Add New Column
var newRect = addNewColumn(columnValue_1);
}
//Function to add new rect is:
function addNewColumn(inputVal)
{
var parentBox = getPosition(currentParentCell);
var maxWidth = getMaxWidth();
var latestY_Value = getLatestY();
var newRect = new joint.shapes.devs.TooledModel({
isInteractive: false,
position: {x: parentBox.x + 1, y: latestY_Value + 25},
size: {width: maxWidth, height: 25},
attrs: {
text: {text: inputVal, fill: 'black', 'font-weight': 'normal', 'font-size': 12},
rect: {
fill: '#fff', opacity: .80, 'stroke-width': 0.3, stroke: '#000'
}
}
});
currentParentCell.embed(newRect);
graph.addCells([newRect]);
currentParentCell.embed(newRect);
graph.addCells([newRect]);
return newRect;
}
How do I fix this?