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);
29 var open_dialog = function(){
33 action: 'Part/part_picker_search',
34 real_id: function() { return $(real).attr('id') },
35 'filter.all:substr::ilike': function(){ return $dummy.val() },
36 'filter.type': function(){ return $type.val() },
37 'column': function(){ return $column.val() },
38 'real_id': function() { return real.id },
44 /* In case users are impatient and want to skip ahead:
45 * Capture <enter> key events and check if it's a unique hit.
46 * If it is, go ahead and assume it was selected. If it wasn't don't do
47 * anything so that autocompletion kicks in. For <tab> don't prevent
48 * propagation. It would be nice to catch it, but javascript is too stupid
49 * to fire a tab event later on, so we'd have to reimplement the "find
50 * next active element in tabindex order and focus it".
52 $dummy.keypress(function(event){
53 if (event.keyCode == 13 || event.keyCode == 9) { // enter or tab or tab
54 // if string is empty asume they want to delete
55 if ($dummy.val() == '') {
60 url: 'controller.pl?action=Part/ajax_autocomplete',
64 type: function() { return $type.val() },
65 column: function() { return $column.val()===undefined ? '' : $column.val() },
66 current: function() { return real.value },
69 success: function (data){
71 if (data.length == 1) {
72 $(real).val(data[0].id);
73 $dummy.val(data[0].description);
74 if (event.keyCode == 13)
75 $('#update_button').click();
81 if (event.keyCode == 13)
86 $dummy.blur(function(){
87 if ($dummy.val() == '')
91 // now add a picker div after the original input
92 var pcont = $('<span>').addClass('position-absolute');
93 var picker = $('<div>');
96 picker.addClass('icon16 CRM--Schnellsuche').click(open_dialog);