Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
1
Help us understand the problem. What is going on with this article?
@r_ishimori

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

More than 1 year has passed since last update.

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

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

1
Help us understand the problem. What is going on with this article?
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.
Sign Up
If you already have a Qiita account Login
1
Help us understand the problem. What is going on with this article?