From: Sven Schöling Date: Thu, 29 Nov 2012 15:37:06 +0000 (+0100) Subject: customer_autocomplete X-Git-Tag: release-3.0.0rc1~6 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=1cd0721d9aa749dda37f3dccaa3da2ba0ebcd2cd;p=kivitendo-erp.git 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. --- diff --git a/SL/Template/Plugin/L.pm b/SL/Template/Plugin/L.pm index c590082cf..4ed65ab29 100644 --- a/SL/Template/Plugin/L.pm +++ b/SL/Template/Plugin/L.pm @@ -396,34 +396,10 @@ sub customer_picker { my ($self, $name, $value, %params) = @_; my $name_e = _H($name); - $self->hidden_tag($name, (ref $value && $value->can('id')) ? $value->id : '') . - $self->input_tag("$name_e\_name", (ref $value && $value->can('name')) ? $value->name : '', %params) . - $self->javascript(<{layout}->add_javascripts('autocomplete_customer.js'); + + $self->hidden_tag($name, (ref $value && $value->can('id') ? $value->id : ''), class => 'customer_autocomplete') . + $self->input_tag("$name_e\_name", (ref $value && $value->can('name')) ? $value->name : '', %params); } # simple version with select_tag diff --git a/js/autocomplete_customer.js b/js/autocomplete_customer.js new file mode 100644 index 000000000..64394556a --- /dev/null +++ b/js/autocomplete_customer.js @@ -0,0 +1,25 @@ +$(function(){ + $('input.customer_autocomplete').each(function(i,real){ + var dummy = $('#' + real.id + '_name'); + $(dummy).autocomplete({ + source: function(req, rsp) { + $.ajax({ + url: 'controller.pl?action=Customer/ajax_autocomplete', + dataType: "json", + data: { + term: req.term, + current: function() { real.val }, + obsolete: 0, + }, + success: function (data){ rsp(data) } + }); + }, + limit: 20, + delay: 50, + select: function(event, ui) { + $(real).val(ui.item.id); + $(dummy).val(ui.item.name); + }, + }); + }) +})