String input with suggest list
Note
The task interface configuration guide describes the features of the HTML/JS/CSS editor. You can also try creating a task interface in Template Builder.
Contains text suggestions that are displayed when the Toloker points the cursor at the input field. There are two types of text suggestions:
-
Universal suggestions used in all tasks.
-
Individual suggestions for different tasks.
-
Set the array of suggestion strings in the JS code (
getTemplateData
method) to include it in the project'sinput data set:Example 1exports.Task = extend(TolokaHandlebarsTask, function (options) { TolokaHandlebarsTask.call(this, options); }, { getTemplateData: function() { var data = TolokaHandlebarsTask.prototype.getTemplateData.apply(this, arguments); data. < array name > = ['string 1', 'string 2', ... 'string n' ]; return data; }, OnRender: function () { //Generated DOM element for the task (available via #getDOMElement()) }, onDestroy: function () { //The task is completed, you can release global resources (if you used them) } }); function extend(ParentClass, constructorFunction, prototypeHash) { constructorFunction = constructorFunction || function () {}; prototypeHash = prototypeHash || {}; if (ParentClass) { constructorFunction.prototype = Object.create(ParentClass.prototype); } for (var i in prototypeHash) { constructorFunction.prototype[i] = prototypeHash[i]; } return constructorFunction; }
Example 2exports.Task = extend(TolokaHandlebarsTask, function (options) { TolokaHandlebarsTask.call(this, options); }, { getTemplateData: function() { var data = TolokaHandlebarsTask.prototype.getTemplateData.apply(this, arguments); data.countries = ['US', 'Germany', 'France']; return data; }, OnRender: function () { //Generated DOM element for the task (available via #getDOMElement()) }, onDestroy: function () { //The task is completed, you can release global resources (if you used them) } }); function extend(ParentClass, constructorFunction, prototypeHash) { constructorFunction = constructorFunction || function () {}; prototypeHash = prototypeHash || {}; if (ParentClass) { constructorFunction.prototype = Object.create(ParentClass.prototype); } for (var i in prototypeHash) { constructorFunction.prototype[i] = prototypeHash[i]; } return constructorFunction; }
-
Add the
{{field type="suggest" name="<output field name>" source=<array name>}}
component to the HTML code. Example:{{field type="suggest" name="result" source=countries allowCustomInput=true}}
-
Add the
{{field type="suggest" name="<output field name>" source=<input field name>}}
component to the HTML code. Example:{{field type="suggest" name="result" source=countries allowCustomInput=true}}
-
Add a field of array string type in the description of input data. Example:
{ "counries": { "type": "array_string", "required": true } }
-
Escape the data and add it to the file with tasks.
Example
Parameters
Parameter |
Description |
Required |
Default value |
|
Field type: |
yes |
no |
|
Attribute for the output data field. Contains the output field name. |
yes |
no |
|
Name of array with suggested strings. For example: |
yes |
no |
|
Whether the Toloker can ignore suggestions and enter their own string. |
no |
|
|
The position of popup hints (displayed if the response didn't pass validation). The position is relative to the input field. Supported values:
|
no |
|
|
The text to display in the empty field. Note If |
no |
no |
|
Shortcut for setting focus on the field. |
no |
no |
|
The value to write in responses if the Toloker didn't fill in the field. Note
|
no |
no |
|
The CSS class for the field. For example: |
no |
|