Hi All,
I am trying to define a block
```javascript
Blockly.defineBlocksWithJsonArray([
{
"type": "variables_get_dynamic",
"message0": "%1 %2",
"args0": [
{
"type": "field_variable",
"name": "VAR",
"variable": "%{BKY_VARIABLES_DEFAULT_NAME}"
},
{
"type": "field_image",
"width": 15,
"height": 15,
"alt": "*"
}
],
"output": null,
"mutator": "my_mutator"
},
]);
```
The initial `src` for `field_image` is unknown(src has to be empty/null at the beginning) so I cannot use the above definition.
So I ended up using
```javascript
Blockly.defineBlocksWithJsonArray([
{
"type": "variables_get_dynamic",
"message0": "%1",
"args0": [
{
"type": "field_variable",
"name": "VAR",
"variable": "%{BKY_VARIABLES_DEFAULT_NAME}"
}
],
"output": null,
"mutator": "my_mutator"
},
]);
(Blockly as any).Constants.VariablesDynamic.MY_MUTATOR = {
mutationToDom: function() {
const container: Element = Blockly.utils.xml.createElement('mutation');
const image: string = this.data;
setImage(this, image);
container.setAttribute('image', image);
return container;
},
domToMutation: function(xmlElement: Element) {
},
};
const setImage = (block: Blockly.BlockSvg, image: string) => {
if (image) {
const name: string = block.getField('VAR').getText();
const currentImage: string = block.getField('IMAGE');
const imgSrc = 'some_img_src';
if (!imgSrc) {
return;
}
block
.appendDummyInput()
.appendField(new Blockly.FieldImage(imgSrc, 35, 35, "*"), 'IMAGE')
}
};
```
The image displayed fine but dragging the block will throw errors
```
blockly_compressed.js?e98f:319 Uncaught TypeError: Cannot read property 'fieldRow' of undefined
at Blockly.InsertionMarkerManager.createMarkerBlock_ (blockly_compressed.js?e98f:319)
at new Blockly.InsertionMarkerManager (blockly_compressed.js?e98f:314)
at new Blockly.BlockDragger (blockly_compressed.js?e98f:333)
at Blockly.TouchGesture.Blockly.Gesture.startDraggingBlock_ (blockly_compressed.js?e98f:436)
at Blockly.TouchGesture.Blockly.Gesture.updateIsDraggingBlock_ (blockly_compressed.js?e98f:433)
at Blockly.TouchGesture.Blockly.Gesture.updateIsDragging_ (blockly_compressed.js?e98f:435)
at Blockly.TouchGesture.Blockly.Gesture.updateFromEvent_ (blockly_compressed.js?e98f:430)
at Blockly.TouchGesture.Blockly.Gesture.handleMove (blockly_compressed.js?e98f:441)
at Blockly.TouchGesture.handleMove (blockly_compressed.js?e98f:677)
at HTMLDocument.h (blockly_compressed.js?e98f:57)
Blockly.InsertionMarkerManager.createMarkerBlock_ @ blockly_compressed.js?e98f:319
Blockly.InsertionMarkerManager @ blockly_compressed.js?e98f:314
Blockly.BlockDragger @ blockly_compressed.js?e98f:333
Blockly.Gesture.startDraggingBlock_ @ blockly_compressed.js?e98f:436
Blockly.Gesture.updateIsDraggingBlock_ @ blockly_compressed.js?e98f:433
Blockly.Gesture.updateIsDragging_ @ blockly_compressed.js?e98f:435
Blockly.Gesture.updateFromEvent_ @ blockly_compressed.js?e98f:430
Blockly.Gesture.handleMove @ blockly_compressed.js?e98f:441
Blockly.TouchGesture.handleMove @ blockly_compressed.js?e98f:677
h @ blockly_compressed.js?e98f:57
8blockly_compressed.js?e98f:441 Uncaught TypeError: Cannot read property 'dragBlock' of null
at Blockly.TouchGesture.Blockly.Gesture.handleMove (blockly_compressed.js?e98f:441)
at Blockly.TouchGesture.handleMove (blockly_compressed.js?e98f:677)
at HTMLDocument.h (blockly_compressed.js?e98f:57)
Blockly.Gesture.handleMove @ blockly_compressed.js?e98f:441
Blockly.TouchGesture.handleMove @ blockly_compressed.js?e98f:677
h @ blockly_compressed.js?e98f:57
blockly_compressed.js?e98f:442 Uncaught TypeError: Cannot read property 'endBlockDrag' of null
at Blockly.TouchGesture.Blockly.Gesture.handleUp (blockly_compressed.js?e98f:442)
at Blockly.TouchGesture.handleUp (blockly_compressed.js?e98f:678)
at HTMLDocument.h (blockly_compressed.js?e98f:57)
``
I am guessing I could be either missing something in the mutation or adding the image field incorrectly.