Fix with auto-complete on insert where list was empty on update when we already have...
authorGuillaume (ioguix) de Rorthais <ioguix@free.fr>
Thu, 23 Sep 2010 00:11:07 +0000 (02:11 +0200)
committerGuillaume (ioguix) de Rorthais <ioguix@free.fr>
Thu, 23 Sep 2010 00:14:07 +0000 (02:14 +0200)
js/ac_insert_row.js

index 120a57982c05d5d9d2ea1193452903f3364fdcc9..cd59e2c5f62f67c8f0c3b8bd820cc1ad4a8db9c3 100644 (file)
@@ -14,15 +14,15 @@ function hideAc() {
 function triggerAc(ac) {
        if (ac) {
                jQuery.ppa.attrs
-                       .keyup(autocomplete)
-                       .keypress(move)
+                       .bind('keyup.ac_action', autocomplete)
+                       .bind('focus.ac_action', autocomplete)
+                       .bind('keypress.ac_action', move)
                        .addClass('ac_field');
        }
        else {
                jQuery.ppa.attrs
                        .removeClass('ac_field')
-                       .unbind('keyup',autocomplete)
-                       .unbind('keypress',move);
+                       .unbind('.ac_action');
        }
 }
 
@@ -125,7 +125,7 @@ function move(event) {
        }
 }
 
-/* open/update the value list on keyup event */
+/* open/update the value list */
 function autocomplete(event) {
 
        /* if pressing enter, fire a click on the selected line */
@@ -133,7 +133,6 @@ function autocomplete(event) {
                if (jQuery.ppa.i > 0) {
                        jQuery.ppa.fklist.find('tr').eq(jQuery.ppa.i).click();
                }
-               hideAc();
                return false;
        }
        /* ignoring 38:up and 40:down */
@@ -152,6 +151,11 @@ function autocomplete(event) {
        }
        /* request the list of possible values asynchronously */
        else {
+               /* if we refresh because of a value update, 
+                * we reset back to offset 0 so we catch values
+                * if list is smaller than 11 values */
+               if (event.type == 'keyup')
+                       jQuery.ppa.o = 0;
                openlist(this);
        }
 
@@ -175,17 +179,19 @@ with(jQuery('tr.acline')) {
 }
 
 jQuery('#fkprev').live('click', function () {
-       jQuery.ppa.o-=11;
+       jQuery.ppa.o -= 11;
        /* get the field that is the previous html elt from the #fklist
-        * and trigger its keyup to refresh the list */
-       jQuery('#fklist').prev().keyup().focus();
+        * and trigger its focus to refresh the list AND actualy 
+        * focus back on the field */
+       jQuery('#fklist').prev().focus();
 });
 
 jQuery('#fknext').live('click', function () {
-       jQuery.ppa.o+=11;
+       jQuery.ppa.o += 11;
        /* get the field that is the previous html elt from the #fklist
-        * and trigger its keyup to refresh the list */
-       jQuery('#fklist').prev().keyup().focus();
+        * and trigger its focus to refresh the list AND actualy 
+        * focus back on the field*/
+       jQuery('#fklist').prev().focus();
 });
 
 jQuery(document).ready(function () {
@@ -209,12 +215,6 @@ jQuery(document).ready(function () {
                        if (e.keyCode == 13 && jQuery.ppa.fklist[0].style.display == 'block')
                                return false;
                });
-
-       /* open the list when the field get the focus */
-       jQuery.ppa.attrs
-               .focus(function (e) {
-                       $(this).keyup();
-               });
        
        /* enable/disable auto-complete according to the checkbox */
        triggerAc(