Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add demo for using ajax to set the users array #10

Open
hadees opened this issue May 5, 2013 · 20 comments
Open

Add demo for using ajax to set the users array #10

hadees opened this issue May 5, 2013 · 20 comments

Comments

@hadees
Copy link

hadees commented May 5, 2013

Could you add an example for using mention.js with a function setting the users array?

@jaykappa
Copy link

Simple solution. Replace:
$("#light").mention({ ... });

with:

$.getJSON('ajaxFile.php', function(data) {
$("#light").mention({
delimiter: '@',
users: data
});
});

PHP file as such, change results array to loop for your query as necessary:
header('Content-Type: application/json');
$results = array();
$results[] = array( 'username' => 'dave');
$results[] = array( 'username' => 'francis');
$results[] = array( 'username' => 'donald');
$results[] = array( 'username' => 'collin');
$results[] = array( 'username' => 'conrad');

echo json_encode($results);

@dsteplight
Copy link

I think it would be a good idea if $.getJSON('ajaxFile.php', function(data) .... was inside of a function call like getNewData(string) { }.... this way the getNewData() could be called every time on the onkeyup event so you can get a filtered result set from ajaxFile.php .

@jaykappa
Copy link

agreed! Was looking to implement that exact solution to build out a dynamic result set.

However can't seem to find a working demo solution, which would pass to PHP a data string (in this case the portion of the username). A onkeyup example would be great. Anything already available?

@dsteplight
Copy link

I just discovered mention.js yesterday. I feel pretty confident that I can create a working example for you @jaykappa . I'll post a link this week or work on a way to update the actual plugin

@jaykappa
Copy link

Amazing, I've got a very pedestrian solution in the works which I'll also post later this week. But involved altering mention.js as opposed to working with it. Biggest problem I had was initiating passing the query.string from "_matcher" and then resetting itemProps in _matcher with the new dataset.

@jaykappa
Copy link

http://www.jay-kapadia.com/mention/demo.html

There's a working demo, however please note this is very bad code and should be re-structured. I can't stress that enough. Also mention.js was altered by adding an ajax call and ajax url to the settings. This call is made in the _sorter function as I found it to be most stable place to change the source data.

To prevent async it's turned off and then back on in the created _updateSource function.

Because the method and code isn't super clean I didn't put it on GitHub, hoping someone can clean this up.

in the PHP file I used the same code as above to return the JSON and "qUser" is the query string to run a "LIKE" search for output (just as a reference).

@mnask
Copy link

mnask commented Aug 28, 2014

im using your plugin , thank you for good job , but why its hang ? when i start typing , it hang till i get result from backend

@jaykappa
Copy link

Are you using the version based on ajax? If you are then probably because the hack created wasn't coded optimally, other issues could be how fast your database returns results. The code could surely still be cleaned up to be more optimized, I'm hoping someone will take the time to do so in the near future.

@mnask
Copy link

mnask commented Aug 28, 2014

yes , based on ajax , and i wish you will fix this .really your plugin very good , i have seen other plugins , but i liked your plugin more , but it will be perfect if this issue will be fixed .
i would like to fix the issue , but to be honest , i dont know exactly what causing this

thank you

@jaykappa
Copy link

Sorry mnask, I wish I could spend some more time to take it to the next level, but I'm swamped with my own projects at the moment.

Here's hoping someone out there on GitHub sees this and can help, fingers crossed.

@iyzl
Copy link

iyzl commented Feb 14, 2015

user result unique setting is not working :)

@AntoineTurmel
Copy link

@jaykappa
To avoid the lag maybe you need to let async true and use debounce ?
I did several try but not successful :(

@jaykappa
Copy link

I'll try to put the debounce in the bootstrap class during the on focus. That should help.

On Wednesday, 14 October 2015, Antoine Turmel [email protected]
wrote:

@jaykappa https://github.com/jaykappa
To avoid the lag maybe you need to let async true and use debounce ?
I did several try but not successful :(


Reply to this email directly or view it on GitHub
#10 (comment)
.

  • Jay Kapadia*
    416.564.4954

@AntoineTurmel
Copy link

@jaykappa
I tried, but doesn't work... it should debounce when the user type something.

@AntoineTurmel
Copy link

@jaykappa
I somehow manage to get debounce working when putting the code into "lookup" section but it's not perfect as it's still fetching the URL for each key pressed.
https://gist.github.com/AntoineTurmel/3513a0cd7f0fc9ca0e1d#file-bootstrap-typeahead-js-L95

Any clue ?

@jaykappa
Copy link

jaykappa commented Nov 4, 2015

@AntoineTurmel I've been playing around but no success yet. It should be set on the listener I thought prior to/on a keypress but failed. I can probably squeeze some time in this weekend to dive in a bit

@AntoineTurmel
Copy link

Using setTimeout is better and works well :)
https://gist.github.com/AntoineTurmel/3513a0cd7f0fc9ca0e1d#file-bootstrap-typeahead-js-L254

@jaykappa
Copy link

jaykappa commented Nov 9, 2015

Boom well done! I still didnt have a adjust code myself, Sorry @AntoineTurmel - but I'll test this out asap!

@Theo4
Copy link

Theo4 commented Jul 26, 2018

Hi there! Do you have a working example of this Ajax call? @AntoineTurmel @jaykappa
Nice job,

@jaykappa
Copy link

@Theo4 I haven't changed the demo in three years but here's a link:
http://www.jay-kapadia.com/mention/demo.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants