jquery autocomplete: works for first value, how to enable it for next?
I'm using autocomplete so user can easly enter data on inputs, like this:
<?
$a = new etiqueta(0, '');
$b = $a->autocomplete_etiquetas();
?>
<script type="text/javascript">
function cargar_autocomplete_etiquetas(){
$("#tags").autocomplete({
source: [<? echo $b; ?>]
});
}
</script>
$a = $b its an array with a result like: 'help','please',i','need','to,'be able to', 'select next item',' with autocomplete';
and i checked the ui documentation, but it doesn't fith with my source method.. any idea? I'm trying like this (edited with Bugai13 aportation):
<?
$a = new etiqueta(0, '');
$b = $a->autocomplete_etiquetas();
?>
<script type="text/javascript">
function cargar_autocomplete_etiquetas(){
$("#tags").autocomplete({
source: [<? echo $b; ?>],
multiple: true,
multipleSeparator: ", ",
matchContains: true
});
}
</script>
but i don't know how to do it.. any idea? are .push and .pop functions from the autocomplete? or shall i define, them?
thanks again!
PS: i'm getting adicted to this site! PS: come on dudes, i think the answer will be very usefull for many people PS: is it allowed to offer paypal reward?
I've use following to get work multiple autocomplete for tags with ',' separator, hope this help your:
It's full my code that work. In my case in parse function items it just json array, try to add parse method:
$("#txtTags").autocomplete(UrlFactory.TAGS_AUTOCOMPLETE_URL, {
matchContains: true,
width: 320,
max: 10,
highlight: false,
multiple: true,
multipleSeparator: ", ",
scroll: true,
scrollHeight: 300,
dataType: "json",
parse: function (data) {
var result = Result.fromJson(data);
var items = result.getJson("Tags");
var arr;
if (items != null)
arr = items.split(",");
return $.map(arr, function (row, i) {
return {
data: row,
value: row,
result: row
}
});
},
onItemSelect: function () {
},
formatItem: function (data, i, n, value) {
if (value != null) {
value = ltrim(value);
value = rtrim(value);
}
return value;
}
});
So, you need something like this:
function cargar_autocomplete_etiquetas(){
$("#tags").autocomplete({
source: [<? echo $b; ?>],
multiple: true,
multipleSeparator: ", ",
matchContains: true
});
}
What does echo $b;
print? I would expect you would need something like echo implode(',', $b)
, or even echo '"' . implode('", "', $b) . '"';
to make this work, if $b really is a PHP array.
Edit: (of course I'm only assuming you're using PHP, but if it <?
s like PHP and $
s like PHP...)
精彩评论