Himanshu Shekhar Himanshu Shekhar - 3 months ago 28
jQuery Question

Twitter like @ or # key search using bootstrap suggest

Please suggest how can I search or autosuggest not only using @ but the # key as well in the same piece of script below. Any regex that simplifies the solution would be appreciated.

$('textarea').suggest('@', {
// or an external JSON data file
data: users,

// style the autocomplete/autusuggest list
map: function(user) {
return {
value: user.username,
text: '<strong>'+user.username+'</strong> <small>'+user.fullname+'</small>'
}
}
});


Link for the same is given here Twitter Like @Mentions Auto Suggesting.
The problem with this is that I want @ and # both keys to be used as search pattern. But in the script above only @ is being used.

Answer

From the DOC, you need to use:

var optsObj = {
  // or an external JSON data file
  data: users,

  // style the autocomplete/autusuggest list
  map: function(user) {
    return {
      value: user.username,
      text: '<strong>' + user.username + '</strong> <small>' + user.fullname + '</small>'
    }
  }
};

$('textarea').suggest({
  '@': optsObj,
  '#': optsObj
});