JQuery autocomplete for multiple fields

Surprisingly, I have not found answers to my question.

I want to create a form in jQuery with two fields.

  • City code.
  • City name.

and when I enter the area code and leave the field. I want autocomplete city name.

I have installed jQuery autocomplete plugin .

and I have the following code:

$(document).ready(function() {
    $("#field_localite").autocomplete('admin/ajax/npa', {
       extraParams: {
           npa: function() { return $("#field_npa").val(); }
       }
    });

    $("#field_npa").blur(function() {
        $("#field_localite").search();
    });
});

      

The problem is that the .search () method. does not trigger autocomplete.

I'm looking for a way to trigger this autocomplete on a field.

Do you know a method or plugin capable of doing this search?

early

BTW: PHP code behavior is fully tested and works, it returns data when the call is made.

+2


a source to share


2 answers


got it.

Finally, I did it differently.

I put autocomplete in the city code field:



$("#field_npa").autocomplete(Drupal.settings.basePath+'admin/ajax/npa', {
   formatItem: formatItem,
   cacheLength: 1,
   minChars:4

}).result(function(event, data, formatted) {
    $("#field_localite").val(data[1]);
});

function formatItem(row) {
        return row[0] + " " + row[1];
}

      

and that did the trick as i wanted.

+1


a source


$("#field_localite").autocomplete("search");

must do the trick.



+1


a source







All Articles