$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' });
}
$.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]);