Revision 1cd0721d
Von Sven Schöling vor etwa 12 Jahren hinzugefügt
SL/Template/Plugin/L.pm | ||
---|---|---|
396 | 396 |
my ($self, $name, $value, %params) = @_; |
397 | 397 |
my $name_e = _H($name); |
398 | 398 |
|
399 |
$self->hidden_tag($name, (ref $value && $value->can('id')) ? $value->id : '') . |
|
400 |
$self->input_tag("$name_e\_name", (ref $value && $value->can('name')) ? $value->name : '', %params) . |
|
401 |
$self->javascript(<<JS); |
|
402 |
function autocomplete_customer (selector, column) { |
|
403 |
\$(function(){ \$(selector).autocomplete({ |
|
404 |
source: function(req, rsp) { |
|
405 |
\$.ajax({ |
|
406 |
url: 'controller.pl?action=Customer/ajax_autocomplete', |
|
407 |
dataType: "json", |
|
408 |
data: { |
|
409 |
column: column, |
|
410 |
term: req.term, |
|
411 |
current: function() { \$('#$name_e').val() }, |
|
412 |
obsolete: 0, |
|
413 |
}, |
|
414 |
success: function (data){ rsp(data) } |
|
415 |
}); |
|
416 |
}, |
|
417 |
limit: 20, |
|
418 |
delay: 50, |
|
419 |
select: function(event, ui) { |
|
420 |
\$('#$name_e').val(ui.item.id); |
|
421 |
\$('#$name_e\_name').val(ui.item.name); |
|
422 |
}, |
|
423 |
})}); |
|
424 |
} |
|
425 |
autocomplete_customer('#$name_e\_name'); |
|
426 |
JS |
|
399 |
$::request->{layout}->add_javascripts('autocomplete_customer.js'); |
|
400 |
|
|
401 |
$self->hidden_tag($name, (ref $value && $value->can('id') ? $value->id : ''), class => 'customer_autocomplete') . |
|
402 |
$self->input_tag("$name_e\_name", (ref $value && $value->can('name')) ? $value->name : '', %params); |
|
427 | 403 |
} |
428 | 404 |
|
429 | 405 |
# simple version with select_tag |
js/autocomplete_customer.js | ||
---|---|---|
1 |
$(function(){ |
|
2 |
$('input.customer_autocomplete').each(function(i,real){ |
|
3 |
var dummy = $('#' + real.id + '_name'); |
|
4 |
$(dummy).autocomplete({ |
|
5 |
source: function(req, rsp) { |
|
6 |
$.ajax({ |
|
7 |
url: 'controller.pl?action=Customer/ajax_autocomplete', |
|
8 |
dataType: "json", |
|
9 |
data: { |
|
10 |
term: req.term, |
|
11 |
current: function() { real.val }, |
|
12 |
obsolete: 0, |
|
13 |
}, |
|
14 |
success: function (data){ rsp(data) } |
|
15 |
}); |
|
16 |
}, |
|
17 |
limit: 20, |
|
18 |
delay: 50, |
|
19 |
select: function(event, ui) { |
|
20 |
$(real).val(ui.item.id); |
|
21 |
$(dummy).val(ui.item.name); |
|
22 |
}, |
|
23 |
}); |
|
24 |
}) |
|
25 |
}) |
Auch abrufbar als: Unified diff
customer_autocomplete
Javascript war nicht in der Lage mehr als ein Feld zu handhaben. Es ist
jetzt ausgelagert in ein Javascript und wird nur bei Bedarf geladen.