Help us understand the problem. What is going on with this article?

EasyAutocompleteを5行で日本語入力変換に対応させる

オートコンプリート機能は日本語変換に対応していない

EasyAutocomplete:http://easyautocomplete.com/guide#sec-functions

ドキュメント通りに実装してみる。

hoge.js
  var options = {
    data: yakinikuData,
    getValue: "name",
    list: {
      match: {
        enabled: true
      },
    },
  };

  let autocomplete = $("#autoComplete");
  autocomplete.easyAutocomplete(options);

ローマ字だけなら問題ない。動く。

3.gif

日本語変換してしまうと、狙い通りに動かない。

変換後の「焼肉」で検索したいのに、「やきにく」で検索される。

4.gif

解決策

参考:https://github.com/pawelczak/EasyAutocomplete/issues/236
参考:https://developer.mozilla.org/ja/docs/Web/Reference/Events/compositionend
以下を追加する。

hoge.js
  var options = {
    data: gon.gurunavis,
    getValue: "name",
    list: {
      match: {
        enabled: true
      },
    },
  };

  let autocomplete = $("#autoComplete");
  autocomplete.easyAutocomplete(options);

  // 以下を追加
  autocomplete.on('compositionend', function () {
    let evt = jQuery.Event("keyup");
    evt.keyCode = 41;
    autocomplete.trigger(evt);
  });

動いた

5.gif

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした