dropdowntoloka

Dropdown list for Toloka project


Could anybody give an advice on how to make dropdown lists appear only after performer types at least 5 characters in the answer field?


Solution

  • your problem with the drop-down lists can be solved like this: Add CustomSuggestSource by pasting the following code above the code of the task (exports.Task), i.e. to the very top of the JS block of your project:

    var IGNORE_INPUT_LENGTH = 5;
    var CustomSuggestSource = Backbone.Model.extend({
    assets: [],
    constructor: function(data, options) {
    this.options = options;
    this.assets = _.clone(data);
    Backbone.Model.apply(this, options);
    },
    /**
    * @param {string} query
    * @returns {string[]}
    */
    filterBy: function(query) {
    if (query.length < IGNORE_INPUT_LENGTH) {
    return [];
    }
    var queryString = query.toLowerCase();
    return _.filter(this.assets, function(str) {
    return str.toLowerCase().indexOf(queryString) >= 0;
    });
    }
    });