Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
Im having an issue with the jquery autocomplete select method

My current code is

$(".Commodities").autocomplete({
source: function (request, response) {
    $.getJSON('url',  function (data) {
            var comms = $.map(data, function (el) {
                 return {
                     label: el.desc,
                     value: el.desc
                     
                 };
             
             });
               response($.ui.autocomplete.filter(comms, request.term));
            
         })   
     },
      minLength: 2,
          select: function( event, ui,el ) {
        $('#commcd').val(ui.item.code);
      
        }
         
});

I'm not really familiar with the ui.item part of the code but I'm assuming it's pulling from the mapped out json. I'm sure that my formatting is off somewhere and I'm assuming its how I used the ui.item property. I'm at a loss but it would be a huge help if anyone could shed a light on this the last step I need to finish this is just passing that extra value to an input field.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Consider the following.

$(".Commodities").autocomplete({
  source: function (request, response) {
    $.getJSON('url?term=' + request.term, function (data) {
      var comms = $.map(data, function (el) {
        return {
          label: el.desc,
          value: el.desc,
          code: el.code
        };     
      });
      response(comms);      
    })   
  },
  minLength: 2,
  select: function(event, ui) {
    $('#commcd').val(ui.item.code);
    return false;
  } 
});

If your URL is an API, it should be able to accept a term or query to help reduce the results. It is always better to do this server-side if possible. Otherwise, you can filter the results as you did.

response($.ui.autocomplete.filter(comms, request.term));
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!