From 31796418f21cbf2c9b31e2b53005f567bc9316df Mon Sep 17 00:00:00 2001
From: Arnaud Fontaine <arnaud.fontaine@nexedi.com>
Date: Thu, 6 Feb 2014 23:12:14 +0900
Subject: [PATCH] erp5_autocompletion_ui: Support properly Input Method Editor
 for autocompletion.

---
 .../jquery.erp5.autocompletion.js.xml                  | 10 +++++++++-
 bt5/erp5_autocompletion_ui/bt/change_log               |  3 +++
 bt5/erp5_autocompletion_ui/bt/revision                 |  2 +-
 product/ERP5Form/MultiRelationField.py                 |  8 +++++++-
 4 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/bt5/erp5_autocompletion_ui/SkinTemplateItem/portal_skins/erp5_autocompletion_ui/jquery.erp5.autocompletion.js.xml b/bt5/erp5_autocompletion_ui/SkinTemplateItem/portal_skins/erp5_autocompletion_ui/jquery.erp5.autocompletion.js.xml
index a7d858019c..899966304b 100644
--- a/bt5/erp5_autocompletion_ui/SkinTemplateItem/portal_skins/erp5_autocompletion_ui/jquery.erp5.autocompletion.js.xml
+++ b/bt5/erp5_autocompletion_ui/SkinTemplateItem/portal_skins/erp5_autocompletion_ui/jquery.erp5.autocompletion.js.xml
@@ -59,6 +59,13 @@ $(function() {\n
             });\n
         };\n
     }\n
+\n
+    function search(event, ui) {\n
+      // Ignore key input if processing with Input Method Editor\n
+      if(event.keyCode == 229)\n
+        return false;\n
+      return true;\n
+    }      \n
 \n
     /*\n
      * Wrapper around jQuery.ui.autocomplete that queries catalog\n
@@ -78,7 +85,8 @@ $(function() {\n
      */\n
     $.fn.ERP5Autocomplete = function(kw) {\n
         return this.autocomplete({source: generateSource(kw),\n
-                                  delay: 600});\n
+                                  delay: 600,\n
+                                  search: search});\n
     };\n
 });\n
 </tal:block>
diff --git a/bt5/erp5_autocompletion_ui/bt/change_log b/bt5/erp5_autocompletion_ui/bt/change_log
index 42486c45c2..8c73e84996 100644
--- a/bt5/erp5_autocompletion_ui/bt/change_log
+++ b/bt5/erp5_autocompletion_ui/bt/change_log
@@ -1,3 +1,6 @@
+2014-02-06 arnaud.fontaine
+* Support properly Input Method Editor for autocompletion.
+
 2014-01-27 arnaud.fontaine
 * RelationField: Implement autocompletion and use it by default once erp5_autocompletion_ui is installed.
 
diff --git a/bt5/erp5_autocompletion_ui/bt/revision b/bt5/erp5_autocompletion_ui/bt/revision
index 3cacc0b93c..ca7bf83ac5 100644
--- a/bt5/erp5_autocompletion_ui/bt/revision
+++ b/bt5/erp5_autocompletion_ui/bt/revision
@@ -1 +1 @@
-12
\ No newline at end of file
+13
\ No newline at end of file
diff --git a/product/ERP5Form/MultiRelationField.py b/product/ERP5Form/MultiRelationField.py
index 1c0eb97b05..6aa081ca14 100644
--- a/product/ERP5Form/MultiRelationField.py
+++ b/product/ERP5Form/MultiRelationField.py
@@ -382,7 +382,13 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget,
 <script type="text/javascript">
 $(document).ready(function() {
   var autocomplete = $("input[name='%s']").ERP5Autocomplete({search_portal_type: %s,
-                                                             search_catalog_key: "%s"});
+                                                             search_catalog_key: "%s"})
+    .keyup(function(event) {
+             // With Input Method Editor, Enter allows to select between choices
+             if(event.keyCode == 13) {
+               $(this).autocomplete("search");
+             }
+  });
 
   autocomplete = autocomplete.data("autocomplete") ?
                  // jQuery UI <= 1.8
-- 
2.30.9