Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Dynamic changes to message

20 views
Skip to first unread message

Bryan Crotaz

unread,
Dec 9, 2024, 11:15:07 AM12/9/24
to Blockly
I have a list of sequential blocks. I want to add the prefix 'Then ' to all but the first event.

I've added a change event handler, and I can successfully detect whether there's a parent. However I can't work out how to neatly change the text.

I've added a field_label, and I've tried two techniques with it.
1. Change the text between '' and 'Then'. This works, but the message is indented when the label is blank - it's adding the space in between %1 and %2.
2. Show/hide the label. This still leaves the extra space in place, but now when I hide then show the label, it renders overlapped with the second field.

What's the correct way to modify the message at run time?

Ronald Bourret

unread,
Dec 9, 2024, 1:23:50 PM12/9/24
to blo...@googlegroups.com
Have you tried Input.insertFieldAt()? It seems to work for me. This extension sets a block change listener that adds "Then" to the start of a statement block on any event:

Blockly.Extensions.register('add_then_on_change', function() {
  this.setOnChange(function(changeEvent) {
    if (!this.getParent()) return;
    const input = this.inputList[0];
    input.insertFieldAt(0, 'Then');
    this.setOnChange(() => {}); // Remove listener
  });
});

If this doesn't help, can you show us your code?

Thanks,

Ronald Bourret
Technical Writer (Provided by Synergis)


--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/blockly/c80a952b-e06e-4e34-b25b-bf21c423f228n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages