From eff6af2885966e0bbe4b614ef03525012cff92aa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Wed, 10 Jul 2013 13:45:56 +0200 Subject: [PATCH] =?utf8?q?Bei=20tab=20und=20enter=20den=20ersten=20full=20?= =?utf8?q?match=20benutzen.=20nur=20wenn=20der=20nicht=20eindeutig=20ist?= =?utf8?q?=20resetten=20oder=20popup=20=C3=B6ffnen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/Part.pm | 12 ++++++++++++ js/autocomplete_part.js | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/SL/Controller/Part.pm b/SL/Controller/Part.pm index 346a5446d..f0ad1ca9a 100644 --- a/SL/Controller/Part.pm +++ b/SL/Controller/Part.pm @@ -51,6 +51,18 @@ sub action_ajax_autocomplete { $self->{parts} = SL::DB::Manager::Part->get_all(query => [ @filter ], limit => $limit); $self->{value} = $::form->{column} || 'description'; + # if someone types something, and hits enter, assume he entered the full name. + # if something matches, treat that as sole match + if ($::form->{prefer_exact}) { + for my $part (@{ $self->{parts} }) { + if ( lc $part->description eq lc $::form->{term} + || lc $part->partnumber eq lc $::form->{term}) { + $self->{parts} = [ $part ]; + last; + } + } + } + $self->render('part/ajax_autocomplete', { layout => 0, type => 'json' }); } diff --git a/js/autocomplete_part.js b/js/autocomplete_part.js index 61280fd93..90e4312f0 100644 --- a/js/autocomplete_part.js +++ b/js/autocomplete_part.js @@ -115,7 +115,7 @@ namespace('kivi', function(k){ $.ajax({ url: 'controller.pl?action=Part/ajax_autocomplete', dataType: "json", - data: ajax_data($dummy.val()), + data: $.extend( ajax_data($dummy.val()), { prefer_exact: 1 } ), success: function (data){ if (data.length == 1) { set_item(data[0]); -- 2.20.1