2

Blockly のカスタム ブロックを作成しており、入力を検証する必要があります。イベントではonchange、入力に無効な値を入力している場合にユーザーに警告したいと思います。

これが私のブロックです:

ここに画像の説明を入力

Blockly.Blocks['motor'] = {
    init: function() {
        this.setHelpUrl('http://www.example.com/');
        this.setColour(65);
        this.appendDummyInput()
            .appendField("motor( ");
        this.appendValueInput("port_number")
            .setCheck("Number");
        this.appendDummyInput()
            .appendField(");");
        this.setInputsInline(true);
        this.setPreviousStatement(true);
        this.setNextStatement(true);
        this.setTooltip('');
    },
    onchange: function(ev) {
        if (this.getFieldValue('port_number') > '3') {
            this.setWarningText('Port must be 0 - 3.');
        } else {
            this.setWarningText(null);
        }
    }
};

Blockly Developers Pageには、入力値を取得する基本的な例があります。しかし、火災undefinedのたびに返品を受け続けています。onchange

これらの入力の検証をどのように処理できますか? 変数、int ブロックなどから入力できるようにする必要があるため、入力用のドロップダウンを作成したくありません。

4

2 に答える 2