How to use the blockly.FieldDropdown function in blockly

To help you get started, we’ve selected a few blockly examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github miguel76 / SparqlBlocks / src / blocks / logic.js View on Github external
init: function() {
    var OPERATORS =
        [[Blockly.Msg.LOGIC_OPERATION_AND, 'AND'],
         [Blockly.Msg.LOGIC_OPERATION_OR, 'OR']];
    this.setHelpUrl(Blockly.Msg.LOGIC_OPERATION_HELPURL);
    this.setColour(HUE);
    this.setOutput(true, 'BooleanExpr');
    this.appendValueInput('A')
        .setCheck(typeExt('BooleanExpr'));
    this.appendValueInput('B')
        .setCheck(typeExt('BooleanExpr'))
        .appendField(new Blockly.FieldDropdown(OPERATORS), 'OP');
    this.setInputsInline(true);
    // Assign 'this' to a variable for use in the tooltip closure below.
    var thisBlock = this;
    this.setTooltip(function() {
      var op = thisBlock.getFieldValue('OP');
      var TOOLTIPS = {
        'AND': Blockly.Msg.LOGIC_OPERATION_TOOLTIP_AND,
        'OR': Blockly.Msg.LOGIC_OPERATION_TOOLTIP_OR
      };
      return TOOLTIPS[op];
    });
  }
});
github miguel76 / SparqlBlocks / src / blocks / order_fields.js View on Github external
// remove all the fields
    while (input.fieldRow.length > 0) {
      input.removeField(input.fieldRow[0].name);
    }
  } else {
    input = limitField ?
              queryBlock.appendDummyInput(inputName) :
              queryBlock.appendValueInput(inputName)
                        .setCheck(typeExt("OrderByValue"));
    if (!limitField && queryBlock.getInput("LIMIT")) {
      queryBlock.moveInputBefore(inputName, "LIMIT");
    }
    // queryBlock.moveInputBefore(inputName, "RESULTS");
  }
  if (dirFieldName) {
    var dirField = new Blockly.FieldDropdown([["▲", "ASC"], ["▼", "DESC"]]);
    if (oldDirValue) {
      dirField.setValue(oldDirValue);
    }
    input.appendField(dirField, dirFieldName);
  }
  if (limitField) {
    input.appendField("  limit to first", otherFieldNames[0])
        .appendField(
          new Blockly.FieldNumber(oldLimitValue || defaultLimit, 0, maxLimit),
          otherFieldNames[1])
        .appendField("rows", otherFieldNames[2]);
  } else {
    input.appendField(
        index > 1 ?
            (!lastOrderField || index > 2 ? ", " : "") +
                (lastOrderField ? "and " : "") + "then by" :
github miguel76 / SparqlBlocks / src / blocks / logic.js View on Github external
];
    var ltrOperators = [
      ['=', 'EQ'],
      ['\u2260', 'NEQ'],
      ['<', 'LT'],
      ['\u2264', 'LTE'],
      ['>', 'GT'],
      ['\u2265', 'GTE']
    ];
    var OPERATORS = this.RTL ? rtlOperators : ltrOperators;
    this.setHelpUrl(Blockly.Msg.LOGIC_COMPARE_HELPURL);
    this.setColour(HUE);
    this.setOutput(true, 'BooleanExpr');
    this.appendValueInput('A');
    this.appendValueInput('B')
        .appendField(new Blockly.FieldDropdown(OPERATORS), 'OP');
    this.setInputsInline(true);
    // Assign 'this' to a variable for use in the tooltip closure below.
    var thisBlock = this;
    this.setTooltip(function() {
      var op = thisBlock.getFieldValue('OP');
      var TOOLTIPS = {
        'EQ': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_EQ,
        'NEQ': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_NEQ,
        'LT': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_LT,
        'LTE': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_LTE,
        'GT': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_GT,
        'GTE': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_GTE
      };
      return TOOLTIPS[op];
    });
    this.prevBlocks_ = [null, null];
github miguel76 / SparqlBlocks / src / blocks / text.js View on Github external
init: function() {
    var TYPES =
        [['MD5', 'MD5'],
         ['SHA1', 'SHA1'],
         ['SHA256', 'SHA256'],
         ['SHA384', 'SHA384'],
         ['SHA512', 'SHA512']];
    this.setHelpUrl('http://www.w3.org/TR/sparql11-query/#func-hash');
    this.setColour(HUE);
    this.appendValueInput('TEXT')
        .setCheck(typeExt('StringExprOrLiteral'))
        .appendField(new Blockly.FieldDropdown(TYPES), 'TYPE')
        .appendField('hash of');;
    this.setOutput(true, 'StringExpr');
    // this.setTooltip(Msg.HASH_TOOLTIP);
  }
});
github miguel76 / SparqlBlocks / src / blocks / text.js View on Github external
// Create either a value 'AT' input or a dummy input.
    if (isAt) {
      this.appendValueInput('AT').setCheck(typeExt('NumberExpr'));
      if (Blockly.Msg.ORDINAL_NUMBER_SUFFIX) {
        this.appendDummyInput('ORDINAL')
            .appendField(Blockly.Msg.ORDINAL_NUMBER_SUFFIX);
      }
    } else {
      this.appendDummyInput('AT');
    }
    if (Blockly.Msg.TEXT_CHARAT_TAIL) {
      this.removeInput('TAIL', true);
      this.appendDummyInput('TAIL')
          .appendField(Blockly.Msg.TEXT_CHARAT_TAIL);
    }
    var menu = new Blockly.FieldDropdown(this.WHERE_OPTIONS, function(value) {
      var newAt = (value == 'FROM_START') || (value == 'FROM_END');
      // The 'isAt' variable is available due to this function being a closure.
      if (newAt != isAt) {
        var block = this.sourceBlock_;
        block.updateAt_(newAt);
        // This menu has been destroyed and replaced.  Update the replacement.
        block.setFieldValue(value, 'WHERE');
        return null;
      }
      return undefined;
    });
    this.getInput('AT').appendField(menu, 'WHERE');
  }
});
github miguel76 / SparqlBlocks / src / blocks / math.js View on Github external
init: function() {
    var OPERATORS =
        [[Blockly.Msg.MATH_ADDITION_SYMBOL, 'ADD'],
         [Blockly.Msg.MATH_SUBTRACTION_SYMBOL, 'MINUS'],
         [Blockly.Msg.MATH_MULTIPLICATION_SYMBOL, 'MULTIPLY'],
         [Blockly.Msg.MATH_DIVISION_SYMBOL, 'DIVIDE']];
    this.setHelpUrl(Blockly.Msg.MATH_ARITHMETIC_HELPURL);
    this.setColour(HUE);
    this.setOutput(true, 'NumberExpr');
    this.appendValueInput('A')
        .setCheck(typeExt('NumberExpr'));
    this.appendValueInput('B')
        .setCheck(typeExt('NumberExpr'))
        .appendField(new Blockly.FieldDropdown(OPERATORS), 'OP');
    this.setInputsInline(true);
    // Assign 'this' to a variable for use in the tooltip closure below.
    var thisBlock = this;
    this.setTooltip(function() {
      var mode = thisBlock.getFieldValue('OP');
      var TOOLTIPS = {
        'ADD': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_ADD,
        'MINUS': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_MINUS,
        'MULTIPLY': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_MULTIPLY,
        'DIVIDE': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_DIVIDE
      };
      return TOOLTIPS[mode];
    });
  }
});
github miguel76 / SparqlBlocks / src / blocks / text.js View on Github external
if (isAt) {
      this.appendValueInput('AT' + n).setCheck(typeExt('NumberExpr'));
      if (Blockly.Msg.ORDINAL_NUMBER_SUFFIX) {
        this.appendDummyInput('ORDINAL' + n)
            .appendField(Blockly.Msg.ORDINAL_NUMBER_SUFFIX);
      }
    } else {
      this.appendDummyInput('AT' + n);
    }
    // Move tail, if present, to end of block.
    if (n == 2 && Blockly.Msg.TEXT_GET_SUBSTRING_TAIL) {
      this.removeInput('TAIL', true);
      this.appendDummyInput('TAIL')
          .appendField(Blockly.Msg.TEXT_GET_SUBSTRING_TAIL);
    }
    var menu = new Blockly.FieldDropdown(this['WHERE_OPTIONS_' + n],
        function(value) {
      var newAt = (value == 'FROM_START') || (value == 'FROM_END');
      // The 'isAt' variable is available due to this function being a closure.
      if (newAt != isAt) {
        var block = this.sourceBlock_;
        block.updateAt_(n, newAt);
        // This menu has been destroyed and replaced.  Update the replacement.
        block.setFieldValue(value, 'WHERE' + n);
        return null;
      }
      return undefined;
    });
    this.getInput('AT' + n)
        .appendField(menu, 'WHERE' + n);
    if (n == 1) {
      this.moveInputBefore('AT1', 'AT2');
github miguel76 / SparqlBlocks / src / blocks / logic.js View on Github external
init: function() {
    var BOOLEANS =
        [[Blockly.Msg.LOGIC_BOOLEAN_TRUE, 'TRUE'],
         [Blockly.Msg.LOGIC_BOOLEAN_FALSE, 'FALSE']];
    this.setHelpUrl(Blockly.Msg.LOGIC_BOOLEAN_HELPURL);
    this.setColour(HUE);
    this.setOutput(true, 'LiteralBoolean');
    this.appendDummyInput()
        .appendField(new Blockly.FieldDropdown(BOOLEANS), 'BOOL');
    this.setTooltip(Msg.LOGIC_BOOLEAN_TOOLTIP);
  }
});
github miguel76 / SparqlBlocks / src / blocks / text.js View on Github external
init: function() {
    var OPERATORS =
        [[Blockly.Msg.TEXT_TRIM_OPERATOR_BOTH, 'BOTH'],
         [Blockly.Msg.TEXT_TRIM_OPERATOR_LEFT, 'LEFT'],
         [Blockly.Msg.TEXT_TRIM_OPERATOR_RIGHT, 'RIGHT']];
    this.setHelpUrl(Blockly.Msg.TEXT_TRIM_HELPURL);
    this.setColour(HUE);
    this.appendValueInput('TEXT')
        .setCheck(typeExt('StringExpr'))
        .appendField(new Blockly.FieldDropdown(OPERATORS), 'MODE');
    this.setOutput(true, 'StringExpr');
    this.setTooltip(Blockly.Msg.TEXT_TRIM_TOOLTIP);
  }
});
github miguel76 / SparqlBlocks / src / blocks / math.js View on Github external
init: function() {
    var PROPERTIES =
        [[Blockly.Msg.MATH_IS_EVEN, 'EVEN'],
         [Blockly.Msg.MATH_IS_ODD, 'ODD'],
         [Blockly.Msg.MATH_IS_PRIME, 'PRIME'],
         [Blockly.Msg.MATH_IS_WHOLE, 'WHOLE'],
         [Blockly.Msg.MATH_IS_POSITIVE, 'POSITIVE'],
         [Blockly.Msg.MATH_IS_NEGATIVE, 'NEGATIVE'],
         [Blockly.Msg.MATH_IS_DIVISIBLE_BY, 'DIVISIBLE_BY']];
    this.setColour(HUE);
    this.appendValueInput('NUMBER_TO_CHECK')
        .setCheck(typeExt('NumberExpr'));
    var dropdown = new Blockly.FieldDropdown(PROPERTIES, function(option) {
      var divisorInput = (option == 'DIVISIBLE_BY');
      this.sourceBlock_.updateShape_(divisorInput);
    });
    this.appendDummyInput()
        .appendField(dropdown, 'PROPERTY');
    this.setInputsInline(true);
    this.setOutput(true, 'BooleanExpr');
    this.setTooltip(Blockly.Msg.MATH_IS_TOOLTIP);
  },
  /**