Skip to content

Calling getField/getFieldValue/setFieldValue without supplying name gets/changes (value of) first unnamed field #4830

@jschanker

Description

@jschanker

Calling block.setFieldValue without supplying the field name for the required second parameter results in the block's first unnamed field being set to the value of the first argument. For example, calling it on a built-in text_print block replaces print with whatever the new value that's passed is. Connected to this, calling block.getField or block.getFieldValue without supplying a name of the field (value) to get returns the block's first unnamed field (value).

To Reproduce

Steps to reproduce the behavior:

  1. Go to https://blockly-demo.appspot.com/static/tests/playground.html
  2. Drag in a text_print block.
  3. Open the Developer console and type Blockly.getMainWorkspace().getAllBlocks()[0].setFieldValue("Blockly")
  4. See the text print change to Blockly.

Expected behavior

Throw an error when calling setFieldValue without specifying the name of the field to set and throw a warning or error when calling getField or getFieldValue without specifying the name of the field (of the value) to get.

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: fieldshelp wantedExternal contributions actively solicitedissue: bugDescribes why the code or behaviour is wrong

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions