select2 - 使用android搜索按钮提交表单

时间:2017-06-10 14:38:49

标签: javascript android jquery jquery-select2

我的网站使用带有搜索框的select2 3.5.3多重选择字段。在移动设备上,当搜索框被聚焦时弹出的键盘包括搜索按钮。目前,搜索按钮不执行任何操作(我假设它的行为类似于'enter'键,select2用于确认选择,但不提交。)

我希望移动键盘的搜索按钮提交用户查询,并且仅当他们已经做出选择时。有没有办法做到这一点?

以下是相关的select2代码:

function formatPerson(person) {
  // select2: template for people results display
  if (person.loading) return person.text;

  if (person.known_for[0]) {
    var known = person.known_for[0].title
  } else {
    var known = ""
  }

  var markup = '<div><object type="image/jpg" data="https://image.tmdb.org/t/p/w45' +
    person.profile_path +
    '"><img id="placeholder" src="/static/images/logo_placeholder.png"></object> <strong>' +
    person.name +
    "</strong> ( <em>" +
    known +
    "</em> )</div>";

  return markup;
}

function formatPersonSelection(person) {
  // select2: how the people results appear once selected
  return person.name;
}

$('.people_query').select2({
  // select2: ajax code for people search
  ajax: {
    url: "https://api.themoviedb.org/3/search/person?api_key=3b6e9eed30447d42a82fa925134de4ff&language=en-US",
    dataType: 'json',
    delay: 250,
    data: function(params) {
      return {
        query: params.term, // search term
      };
    },
    processResults: function(data, params) {
      return {
        // "data" is the object returned, "results" is the name of the array in the object
        results: data.results,
      };
    },
    cache: true
  }, // ajax
  escapeMarkup: function(markup) {
    return markup;
  }, // custom formatter from Select2
  minimumInputLength: 3,
  language: {
    inputTooShort: function() {
      return 'Search for a person...';
    }
  },
  maximumSelectionLength: 2,
  templateResult: formatPerson,
  templateSelection: formatPersonSelection,

}); //select2 params

0 个答案:

没有答案