From 1cd0721d9aa749dda37f3dccaa3da2ba0ebcd2cd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Thu, 29 Nov 2012 16:37:06 +0100 Subject: [PATCH] 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. --- SL/Template/Plugin/L.pm | 32 ++++---------------------------- js/autocomplete_customer.js | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 28 deletions(-) create mode 100644 js/autocomplete_customer.js 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); + }, + }); + }) +}) -- 2.20.1