ivirabyan / jquery-mentions

Adds mentioning support to your text fields.
http://ivirabyan.github.io/jquery-mentions/
MIT License
114 stars 49 forks source link

Ajax call #15

Closed charlie-eth closed 9 years ago

charlie-eth commented 9 years ago

Hello,

First thank you for the plugin, I've tried many others and yours is by far the best.

Just wondering how I would make a remote ajax call with a parameter? (if I type @BR to make a search on BR in my database and return a json array)

Thank you!

ivirabyan commented 9 years ago

Just pass a url, which does the search, to the source param of the plugin, like this $('textarea').mentionsInput({source: 'http://example.com/users.json'})

charlie-eth commented 9 years ago

But how can I pass the search query?

ivirabyan commented 9 years ago

When you type @BR, plugin queries url http://example.com/users.json?term=BR

charlie-eth commented 9 years ago

Oh I get it, thank you very much!

Just another question, why does the input background needs to be transparent for the highlight to work?

I changed line 323 from transparent to white and the hightlight wouldn't work after that!

charlie-eth commented 9 years ago

Also, whilst I have you, is there a way to get the response from getValue as json?

I get this format @username which is gonna need some playing around with preg_match to achieve what I want (storing them nicely in a database) or am I missing something again?

Sorry about all the questions, jquery isn't really my thing!

ivirabyan commented 9 years ago

A note about background, as far as I understand you are having issues with non-white background, so that your input is also non-white. If that's the case, I've just fixed that issue, download updated code.

ivirabyan commented 9 years ago

Can you provide an example of desired response from getValue method? What do you mean by "storing them nicely in a database"?

The standard approach is to pass the string to the server, and then parse the string with regexp to replace mentions by links.

charlie-eth commented 9 years ago

Regarding the highlighter, the issue is that the input background needs to be transparent for the background-color to work on the highlighter but it's not a bug.

A json array like so {name: 'alex', uid: 'user:1'} Getting that from getValue would be a lot easier in my opinion.

charlie-eth commented 9 years ago

This is my input on your latest commit:

Alt Text

Let me know if you want to see it live.

Edit: Nevermind, this is happening because my input is 34px when I initialise the plugin and becomes 76px on focus (but the hightlighter size is already set).

Thanks a lot for your help and the plugin, I won't take anymore of your time!

ivirabyan commented 9 years ago

What you need is an array of all mentions, contained in an input, ignoring any text, right? Such a method could be added easily, since this information is already stored inside of the plugin.

I'll add an issue for your problem with focused textarea, I think it's quite a common scenario.

charlie-eth commented 9 years ago

Would be great to see that method added to easily get the value of the tags without messing about with regex.

Ok thanks, in the meantime, I'm just changing the size of .highlighter on focus

ivirabyan commented 9 years ago

I've added method getMentions

charlie-eth commented 9 years ago

Awesome, thank you!