2 $('input.part_autocomplete').each(function(i,real){
3 var $dummy = $('#' + real.id + '_name');
4 var $type = $('#' + real.id + '_type');
5 var $column = $('#' + real.id + '_column');
7 source: function(req, rsp) {
9 url: 'controller.pl?action=Part/ajax_autocomplete',
13 type: function() { return $type.val() },
14 column: function() { return $column.val()===undefined ? '' : $column.val() },
15 current: function() { return real.value },
18 success: function (data){ rsp(data) }
23 select: function(event, ui) {
24 $(real).val(ui.item.id);
25 $dummy.val(ui.item.name);
28 /* In case users are impatient and want to skip ahead:
29 * Capture <enter> key events and check if it's a unique hit.
30 * If it is, go ahead and assume it was selected. If it wasn't don't do
31 * anything so that autocompletion kicks in. For <tab> don't prevent
32 * propagation. It would be nice to catch it, but javascript is too stupid
33 * to fire a tab event later on, so we'd have to reimplement the "find
34 * next active element in tabindex order and focus it".
36 $dummy.keypress(function(event){
37 if (event.keyCode == 13 || event.keyCode == 9) { // enter or tab or tab
38 // if string is empty asume they want to delete
39 if ($dummy.val() == '') {
44 url: 'controller.pl?action=Part/ajax_autocomplete',
48 type: function() { return $type.val() },
49 column: function() { return $column.val()===undefined ? '' : $column.val() },
50 current: function() { return real.value },
53 success: function (data){
55 if (data.length == 1) {
56 $(real).val(data[0].id);
57 $dummy.val(data[0].description);
58 if (event.keyCode == 13)
59 $('#update_button').click();
63 if (event.keyCode == 13)
68 $dummy.blur(function(){
69 if ($dummy.val() == '')
73 // now add a picker div after the original input
74 var pcont = $('<span>').addClass('position-absolute');
75 var picker = $('<div>');
78 picker.addClass('icon16 CRM--Schnellsuche').click(function(){
82 action: 'Part/part_picker_search',
83 real_id: function() { return $(real).attr('id') },
84 'filter.all:substr::ilike': function(){ return $dummy.val() },
85 'filter.type': function(){ return $type.val() },
86 'column': function(){ return $column.val() },
87 'real_id': function() { return real.id },