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');
}
}
}
}
-/* 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 */
if (jQuery.ppa.i > 0) {
jQuery.ppa.fklist.find('tr').eq(jQuery.ppa.i).click();
}
- hideAc();
return false;
}
/* ignoring 38:up and 40:down */
}
/* 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);
}
}
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 () {
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(