php - at.js can't use remote filter no drop-down displayed

994

I've been trying to implement @mentions for my php application using the At.js library in version 1.5.1 from https://github.com/ichord/At.js

When i typing @ and something after, i see an ajax query in firebug, but i don't see the drop-down to select the differents names.

My javascript code used is the following :

$('#editor').atwho({
    at: "@",
    displayTpl:"<li data-value='${key}'>${username} <img src='${avatar}' height='20' width='20' /></li>",
    callbacks: {
        remoteFilter: function(query, callback) {
        if(query.length > 0) {
            $.ajax({
                url: $( "#url_mentions" ).val(),
                    data: {
                        search : query
                    },
                    done: function(data) {
                        callback(data.users);
                    }
                });
            }
        }
    }
});

The json which is returned by calling the url directly in browser :

{"users":[{"key":"[mention userid=742]admin[\/mention]","userid":"1742","username":"admin","avatar":"<img class=\"kavatar\" src=\"http:\/\/jfconnectoquickstart\/media\/tr\/avatars\/resized\/size24\/cs\/s_nophoto.png\" width=\"24\" height=\"24\"  alt=\"admin's Avatar\" \/>"},{"key":"[mention userid=743]jack[\/mention]","userid":"743","username":"jack","avatar":"<img class=\"kavatar\" src=\"http:\/\/jfconnectoquickstart\/media\/tr\/avatars\/resized\/size24\/cs\/s_nophoto.png\" width=\"24\" height=\"24\"  alt=\"jack's Avatar\" \/>"}]}

The HTML part :

<div >
  <label >Message</label>
  <div >
    <textarea name="message" id="editor" rows="12" tabindex="7"
       required="required"></textarea>
  </div>
</div>

Do-you have an idea to fix it ?

Thanks by advance

14

Answer

Solution:

Little late but might help others.

You must add "searchKey" parameters (see the first parameter)

$('#editor').atwho({
searchKey: 'username', // this is what missing
at: "@",
displayTpl:"<li data-value='${key}'>${username} <img src='${avatar}' height='20' width='20' /></li>",
callbacks: {
    remoteFilter: function(query, callback) {
    if(query.length > 0) {
        $.ajax({
            url: $( "#url_mentions" ).val(),
                data: {
                    search : query
                },
                done: function(data) {
                    callback(data.users);
                }
            });
        }
    }
}

});

People are also looking for solutions to the problem: php - How to send get variables in the url without kill previous sent get variables?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.