Skip to content

Commit 238837a

Browse files
authored
chore: Change setEnabled to setDisabledReason (#2616)
1 parent 6a13b4f commit 238837a

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

codelabs/validation_and_warnings/validation_and_warnings.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ Depending on the severity of the issue, this might be sufficient for your custom
239239

240240
![A Blockly workspace with disabled break and continue blocks.](disabled_break.png)
241241

242-
You can disable a block using `this.setEnabled(false)`, although there are some caveats: disabled blocks can't be dragged out of the toolbox flyout, and the act of disabling a block usually adds an event to Blockly's undo history. That's probably not the behavior you want when validating a block, so you can avoid both of these effects with the following code, which you should put inside the change listener function after setting the warning text:
242+
You can disable a block using `this.setDisabledReason(true, 'reason')`, although there are some caveats: disabled blocks can't be dragged out of the toolbox flyout, and the act of disabling a block usually adds an event to Blockly's undo history. That's probably not the behavior you want when validating a block, so you can avoid both of these effects with the following code, which you should put inside the change listener function after setting the warning text:
243243

244244
```js
245245
// Disable invalid blocks (unless it's in a toolbox flyout,
@@ -248,7 +248,7 @@ You can disable a block using `this.setEnabled(false)`, although there are some
248248
const initialGroup = Blockly.Events.getGroup();
249249
// Make it so the move and the disable event get undone together.
250250
Blockly.Events.setGroup(event.group);
251-
this.setEnabled(valid);
251+
this.setDisabledReason(!valid, 'Invalid range');
252252
Blockly.Events.setGroup(initialGroup);
253253
}
254254
```

examples/validation-and-warnings-codelab/complete-code/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Blockly.Extensions.register('list_range_validation', function () {
5050
const initialGroup = Blockly.Events.getGroup();
5151
// Make it so the move and the disable event get undone together.
5252
Blockly.Events.setGroup(event.group);
53-
this.setEnabled(valid);
53+
this.setDisabledReason(!valid, 'Invalid range');
5454
Blockly.Events.setGroup(initialGroup);
5555
}
5656
});

0 commit comments

Comments
 (0)