Try this:
myDiagram.nodeTemplate.contextMenu =
$(go.Adornment, "Auto",
$(go.Shape, "RoundedRectangle", { fill: "lightgray" }),
$(go.Panel, "Vertical",
{ defaultStretch: go.GraphObject.Horizontal, padding: 5 },
$(go.TextBlock, "Enter texts:", { font: "bold 11pt sans-serif" }),
$(go.TextBlock, {
name: "T1", isActionable: true, background: "whitesmoke", margin: 1,
click: function(e, tb) {
e.diagram.commandHandler.editTextBlock(tb);
}
}, new go.Binding("text", "text")),
$(go.TextBlock, {
name: "T2", isActionable: true, background: "whitesmoke", margin: 1,
click: function(e, tb) {
e.diagram.commandHandler.editTextBlock(tb);
}
}, new go.Binding("text", "text2")),
$(go.Panel, "Horizontal",
{ stretch: go.GraphObject.None, alignment: go.Spot.Center },
$("Button",
$(go.TextBlock, "Accept"),
{
margin: 2,
click: function(e, button) {
var infopanel = button.part;
e.diagram.startTransaction();
e.diagram.model.setDataProperty(infopanel.data, "text", infopanel.findObject("T1").text);
e.diagram.model.setDataProperty(infopanel.data, "text2", infopanel.findObject("T2").text);
e.diagram.remove(infopanel);
e.diagram.commitTransaction("changed some text");
}
}),
$("Button",
$(go.TextBlock, "Cancel"),
{
margin: 2,
click: function(e, button) {
var infopanel = button.part;
e.diagram.startTransaction();
e.diagram.remove(infopanel);
e.diagram.commitTransaction("cancel info");
}
})
)
)
);
myDiagram.nodeTemplate.contextClick = function(e, node) {
e.handled = true; // don't execute standard behavior, which shows the obj.contextMenu
var infopanel = node.contextMenu;
infopanel.position = e.documentPoint;
e.diagram.add(infopanel);
infopanel.data = node.data;
};
I did not use TwoWay Binding on the TextBlocks, just to show that the changes made in the “Accept” Button’s click event handler could be completely independent of the initial TextBlock values.
Two Tools cannot operate simultaneously, so rather than using the regular ContextMenuTool, the node’s contextClick event handler manually shows the context menu. Note how it sets InputEvent.handled to true to prevent the normal behavior of having the ContextMenuTool run to show the GraphObject.contextMenu.
The click event on the TextBlocks explicitly invoke CommandHandler.editTextBlock to start the TextEditingTool. The click events would not normally be noticed for parts in the “Tool” layer, but setting GraphObject.isActionable will allow clicks to be handled normally.
We ought to redesign things so that this is more natural to implement.