-
-
Notifications
You must be signed in to change notification settings - Fork 256
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
Can anyone help with Autocomplete? #233
Comments
You can use bundled textcomplete plugin, <script src="https://cdn.rawgit.com/yuku-t/jquery-textcomplete/v1.3.4/dist/jquery.textcomplete.js"></script> and after that $(document).ready(function() {
$("#emojionearea1").emojioneArea({
pickerPosition: "right",
tonesStyle: "bullet",
autocomplete: true,
events: {
ready: function() {
this.editor.textcomplete([{
id: 'emojionearea',
match: /\B@([\-\d\w]*)$/,
search: function (term, callback) {
// this code must be replaced with your
// load mentions from ajax
var mentions = ['Peter', 'Tom', 'Anne'];
callback($.map(mentions, function (mention) {
return mention.indexOf(term) === 0 ? mention : null;
}));
},
template: function (value) {
return '<b>' + value + '</b> ';
},
replace: function (value) {
return '<b>@' + value + '</b> ';
},
cache: true,
index: 1
}]);
}
}
});
}); Example: https://jsfiddle.net/1v03Lqnu/898/ |
Hi Mervick, First of all congratulations for this emoji plugin. I think is the best we can find now. But I have the same problem as described is this discussion. I tried all the codes I could and I checked everything about what's showing here and textcomplete. I want to associate your plugin and a mention autocomplete code but I can't reach my database table to retrieve the datas. When I type @ it's showing [object Object]. I tried all I know to debug. With no result. If only you could help please ! If you would just reply and I'll show to you the code I did. Thanks a lot and see you soon ! |
$(document).ready(function() {
$("#emojionearea1").emojioneArea({
pickerPosition: "right",
tonesStyle: "bullet",
autocomplete: true,
events: {
ready: function() {
$.ajax('url/to')
.success(data) {
this.editor.textcomplete([{
id: 'emojionearea',
match: /\B@([\-\d\w]*)$/,
search: function (term, callback) {
callback($.map(data, function (mention) {
return mention.indexOf(term) === 0 ? mention : null;
}));
},
template: function (value) {
return '<b>' + value + '</b> ';
},
replace: function (value) {
return '<b>@' + value + '</b> ';
},
cache: true,
index: 1
}]);
});
}
}
});
}); |
Good evening Mervick. Thank you for the reply. I try as soon as possible and I let you know. Thanks again and see you soon ! |
Hi Mervick, Some news : I should have adapted your code to fit with the most recent jQuery version : $("#content").emojioneArea({
}); Console says : Uncaught TypeError: Cannot read property 'textcomplete' of undefined I tried to install inside the js file : {
Not working as well. Maybe I did something wrong. Thanx anyway ! |
Add this script to head <script src="https://cdn.rawgit.com/yuku-t/jquery-textcomplete/v1.3.4/dist/jquery.textcomplete.js"></script> |
I have done it already. That changes nothing... |
@LouisSyfer , if you want my help. please first format your code |
I would like to. Sorry I don't know why it did not... |
Maybe this one is the best. But I don't know why I get [object Object] ... Sure I'm better in PHP !! $("#content").emojioneArea({
autocomplete:true,
events:{
ready: function() {
this.editor.textcomplete([{
match: /(^|\s)@(\w*)$/,
dataType: "json",
search: function (term, callback) {
// this code must be replaced with your
// load mentions from ajax
$.getJSON("mention_autocomplete2.php", { q: term })
.done(function (resp) { callback(resp); })
.fail(function () { callback([]); });
callback($.map(term, function (mention) {
return mention.indexOf(term) === 0 ? mention : null;
}));
},
template: function (value) {
return '<b>' + value + '</b> ';
},
replace: function (value) {
return '<b>@' + value + '</b> ';
},
cache: true,
index: 1
}]);
}
}
});
But maybe the problem come from the php side...
session_start();
include_once("config/database.php");
include_once("includes/functions.php");
include_once("includes/constants.php");
if(isset($_POST['term'])){
$term= $_POST['term'];
//$term= $_GET['term'];
$query = $db->prepare('SELECT * FROM user
WHERE mention_user LIKE :term');
$query->execute(array('term' => '%'.$term.'%'));
$array = array();
?>
<?php
while($donnee = $query->fetch())
{
array_push($array, $donnee["mention_user"]);
//array_push($array, $donnee["id_user"]);
?>
<?php
} ?>
<?php
echo json_encode($array);
}
?>
|
Your code is terrible! At least you have error in the php side, $.getJSON("mention_autocomplete2.php", { q: term }) so in php you should get search param from $_GET['q'] but you use if (isset($_POST['term'])) {
$term= $_POST['term']; |
Well I think I have already tried this ($_GET[‘q ‘] instead of $_POST[‘term’]), I will try again and let you know... |
IT'S WORKING ! Almost... I mean you can retrieve datas from your table, the autocomplete works, but like a normal one : you type @ at the beginning of the textarea but I have to make a "carriage" return if I want to mention other user. But you can't : The code : $("#content").emojioneArea({
autocomplete:true,
events:{
ready: function() {
this.editor.textcomplete([{
match: /(^|\s)@(\w*)$/,
dataType: "json",
search: function (term, callback) {
// this code must be replaced with your
// load mentions from ajax
$.getJSON("mention_autocomplete2.php", { q: term })
.done(function (resp) { callback (resp); })
.fail(function (resp) { callback([resp]); });
callback($.map(term, function (mention) {
return mention.indexOf(term) === 0 ? mention : null;
}));
},
template: function (value) {
return '<b>' + value + '</b> ';
},
replace: function (value) {
return '<b>@' + value + '</b> ';
},
cache: true,
index: 1
}]);
}
}
});
<?php
session_start();
include_once("config/database.php");
include_once("includes/functions.php");
include_once("includes/constants.php");
$term= $_GET['q'];
$query = $db->prepare('SELECT * FROM user WHERE mention_user LIKE :q');
$query->execute(array('q' => '%'.$term.'%'));
$array = array();
?>
<?php
while($donnee = $query->fetch())
{
array_push($array, $donnee["mention_user"]);
?>
<?php } ?>
<?php
header('Content-Type: application/json');
echo json_encode($array);
?> |
It's ok Mervick it's working fine THANKS A LOT ! I just deleted "index:1" at the end of the code. I'm going to test it again but for the moment THAT WORKS pefectly ! |
Im using a library to autocomplete keywords but I can't get it working with Emojionearea
The following fiddle has 2 textareas one with emojionearea and one without; only the latter is working for autocomplete when you type "@"
https://jsfiddle.net/ukLaz8cm/134/
Can anyone help? JS is not my primary language.
The text was updated successfully, but these errors were encountered: