1

I'm trying to make this: http://jsfiddle.net/F9tMx/ work in a way that i can propose to the user who is typing separate suggestions from the availableTags Array.

Basically I'd like to add the same function that is present here on SO when someone is adding a comment to a questions and types the '@' character (a list of user appears if the first character[s] match someone who made activity on the page).

Anyway, I've seen that the minLength parameter is ignored. While the plugin is indeed able to separate words and match against the last word typed, once that the last word is actually empty (last == '') the plugin will propose ALL the elements in the availableTags Array, even if minLength is setted to a number greater than 1.

is there a way I could fix this on your opinion?

here's how I'd like it to behave, but of course it's raising an error http://jsfiddle.net/F9tMx/3/

sathia
  • 2,192
  • 2
  • 24
  • 42
  • 1
    Hiya, you should take a look here I did this for someone recently and jsfiddle is there as well: http://stackoverflow.com/questions/10060536/jquery-autocomplete-mention/10060665#10060665 , D'uh obviously you can make it work for your need any who setting it as comment fro your help, :) have a good one, cheers! – Tats_innit Apr 11 '12 at 10:47
  • thanks! I'm working on it, I need to be able to pick more than one suggested item. at this moment once one is picked the previous will lose its @ symbol. – sathia Apr 11 '12 at 11:06
  • cool! thanks for your tips. it's almost ok now. http://jsfiddle.net/F9tMx/5/ I miss only the fact that once a few characters are on the textarea if you press '@' alone it will propose all the elements on the array. I have no idea how to prevent this though.. – sathia Apr 11 '12 at 11:34
  • 1
    Hiya All good, glad it helped,sure I will reply for rest of the issue soon! :) have a good one, cheers – Tats_innit Apr 11 '12 at 19:06
  • Hiya, do you need further help for this, If you agree I can set this as answer for future refernce and you can accept it as answer? have a good one, cheers! – Tats_innit Apr 12 '12 at 02:53
  • legend mate, setting up now :) cheers! – Tats_innit Apr 12 '12 at 07:22

1 Answers1

1

Hiya cool using @ working demo here: http://jsfiddle.net/67dxH/

so: here is the answer which I replied and helped to someone else: jquery autocomplete @mention

Code segment

this statement will do the trick if (request.term.indexOf("@") >= 0) { rest code is in jdfiddle

.autocomplete({
        source: function(request, response) {
            if (request.term.indexOf("@") >= 0) {
                $("#loading").show();
                getTags(extractLast(request.term), function(data) {
                    response($.map(data.tags, function(el) {
                        return {
                            value: el.name,
                            count: el.count
                        }
                    }));
                    $("#loading").hide();                    
                });
            }
        },

Have a nice one!

cheers!

Community
  • 1
  • 1
Tats_innit
  • 33,991
  • 10
  • 71
  • 77
  • In this jsfiddle the wrong behavior is still there. once you have selected at least one tag if you press @ again it will propose the whole list (and if you select a new tag the former will disappear). here's how I fixed it: http://jsfiddle.net/F9tMx/6/ the only thing that is bugging me now is that it won't match for the few characters a user inserts but it matches in a very lax way. I'd like that it could propose only @user after pressing @u instead of all the tags wich contains the "u" character.. I'm stuck with this now.. – sathia Apr 12 '12 at 07:40
  • 1
    @sathia hmm okies take a look in here bruv: http://jsfiddle.net/ekzMN/8/ should help read the code where ** Iterate through autocomplete results** hope this helps, :) cheers. – Tats_innit Apr 12 '12 at 07:49
  • @sathia or take a look in here: you probably just need to write a matcher: http://forum.jquery.com/topic/autocomplete-max-option-and-first-letter ; me heading for dinner probably look into this latter but please let me know if this helps oh and please accept the answer if it helps, :) cheers! – Tats_innit Apr 12 '12 at 08:09
  • http://jsfiddle.net/F9tMx/11/ here it is, working as I wish. thanks for your help, can it be improved on your opinion? – sathia Apr 12 '12 at 09:16
  • 1
    @sathia sup, looks good man! :)) but I reckon keep it more open search i.e. @ u giving back anything with u; but thats your requirement then keep it the first character search! have a nice one! cheerios! – Tats_innit Apr 12 '12 at 09:44