A Blockly multilineinput field.
npm install @blockly/field-multilineinputA Blockly multiline input field and
associated block.
#### Multiline input field
#### Multiline input field with editor open
!The same block with editor open.
#### Multiline input on collapsed block
```
yarn add @blockly/field-multilineinput
``
npm install @blockly/field-multilineinput --save
This plugin adds a field of type FieldMultilineInput that is registered with'field_multilinetext'
the name . It is a subclass of Blockly.FieldInput.
This field stores a string as its value and a string as its text. Its value is
always a valid string, while its text could be any string entered into its
editor. Unlike a text input field, this field also supports newline characters
entered in the editor.
The constructor for this field accepts three optional parameters:
- value: The default text. Defaults to "".validator
- : A function that is called to validate what the user entered.config
- : An object with three optional properties:maxLines
- : The maximum number of lines displayed before scrollingInfinity
functionality is enabled. Defaults to .spellcheck
- : Whether spell checking is enabled. Defaults to true.tooltip
- : A tooltip.
If you want to use only the field, you must register it with Blockly. You can
do this by calling registerFieldMultilineInput before instantiating your
blocks. If another field is registered under the same name, this field will
overwrite it.
`js
import * as Blockly from 'blockly';
import {registerFieldMultilineInput} from '@blockly/field-multilineinput';
registerFieldMultilineInput();
Blockly.Blocks['test_field_multilineinput'] = {
init: function () {
this.appendDummyInput()
.appendField('multilineinput: ')
.appendField(
new FieldMultilineInput('some text \n with newlines'),
'FIELDNAME',
);
},
};
`
`js
import * as Blockly from 'blockly';
import {registerFieldMultilineInput} from '@blockly/field-multilineinput';
registerFieldMultilineInput();
Blockly.defineBlocksWithJsonArray([
{
"type": "test_field_multilinetext",
"message0": "multilineinput: %1",
"args0": [
{
"type": "field_multilinetext",
"name": "FIELDNAME",
"text": "some text \n with newlines"
}
}]);
`
#### Spellcheck
The setSpellcheck function can be used to set whether the field spellchecks
its input text or not. Spellchecking is on by default.
!An animation showing multiline text input fields with and without
spellcheck.
This applies to individual fields. If you want to modify all fields change the
Blockly.FieldMultilineInput.prototype.spellcheck_ property.
#### Validation
A multiline text input field's value is a string, so any validators must accept
a string and return a string, null, or undefined.
Here is an example of a validator that removes all 'a' characters from the
string:
``
function(newValue) {
return newValue.replace(/a/gm, '');
}
!An animation showing validation.
#### JSON
The JSON for a multiline text input field looks like so:
`json`
{
"fields": {
"FIELDNAME": "line1\nline2"
}
}
where FIELDNAME is a string referencing a multiline text input field, and the
value is the value to apply to the field. The value follows the same rules as
the constructor value.
#### XML
The XML for a multiline text input field looks like so:
`xml`
where the field's name attribute contains a string referencing a multiline
text input field, and the inner text is the value to apply to the field. The
inner text value follows the same rules as the constructor value.
This package also provides a simple block containing a multiline input
field. It has generators in JavaScript, Python, PHP, Lua, and Dart.
You can install the block by calling textMultiline.installBlock().installBlock
This will install the block and all of its dependencies, including the
multiline input field. When calling you can supply one orCodeGenerator
more instances (e.g. javascriptGenerator), and the install
function will also install the correct generator function for the
corresponding language(s).
`js
import {javascriptGenerator} from 'blockly/javascript';
import {dartGenerator} from 'blockly/dart';
import {phpGenerator} from 'blockly/php';
import {pythonGenerator} from 'blockly/python';
import {luaGenerator} from 'blockly/lua';
import {textMultiline} from '@blockly/field-multilineinput';
// Installs the block, the field, and all of the language generators.
textMultiline.installBlock({
javascript: javascriptGenerator,
dart: dartGenerator,
lua: luaGenerator,
python: pythonGenerator,
php: phpGenerator,
});
`
- setMaxLines: Sets the maximum number of displayed lines beforegetMaxLines
scrolling functionality is enabled.
- : Returns the maximum number of displayed lines beforesetSpellcheck
scrolling functionality is enabled.
- : Sets whether spell checking is enabled.getSpellcheck`: Returns whether spell checking is enabled.
-
Apache 2.0