2

Surprisingly, I didn't find any answers to my question.

I want to make a form on jQuery with two fields.

  1. City Code.
  2. City Name.

and when I enter a city code and go out of the field. I want an autocomplete on the city name.

I Installed the 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. doesnt launch the autocomplete.

I'm looking for a method to trigger this autocomplete search on the field.

do you know a way or a plugin able to do this search ?

thanks in advance

BTW : the PHP code behin is totally tested and works, it returns the data when doing the call.

2 Answers 2

1

$("#field_localite").autocomplete("search"); should do the trick.

Sign up to request clarification or add additional context in comments.

2 Comments

Wait, are you talking about the jQueryUI Autocomplete?
no, I wasn't talking about the jQueryUI Autocomplete, but the one on bassistance.de
1

got it.

finally I did it another way.

I put the autocomplete on 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 this did the trick as I wanted.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.