Answer the question
In order to leave comments, you need to log in
Why does inserting search results into input not work?
It is necessary that when typing characters into the input, knock out the search results for the json array, into this very input. For this I used the "ui.autocomplete" library. But something does not work, I can not understand the reason. Who has already worked with this library, tell me what's wrong.
Below is my script to illustrate the problem:
<input type="text" id="myinput">
$(function() {
var projects = [
{
value: "shrek",
label: "шрек, шрек",
desc: "мультфильм шрек 2",
icon: "shrek.jpg"
},
{
value: "рождественская история",
label: "мультфильм рождественская история",
desc: "мультфильм рождественская история",
icon: "cristmas.jpg"
},
{
value: "ледниковый период",
label: "мультфильм ледниковый период",
desc: "мультфильм ледниковый период",
icon: "lp.jpg"
}
,
{
value: "simpsoni",
label: "симпсоны",
desc: "описание, описание, описание...",
icon: "simpsoni.jpg"
}
];
});
$( "#myinput" ).autocomplete({
minLength: 0,
source: projects,
focus: function( event, ui ) {
$( "#myinput" ).val( ui.item.label );
return false;
},
select: function( event, ui ) {
$( "#myinput" ).val( ui.item.label );
$( "#myinput-id" ).val( ui.item.value );
$( "#myinput-description" ).html( ui.item.desc );
$( "#myinput-icon" ).fadeOut('slow',function(){
$(this).attr( "src", "images/" + ui.item.icon ).fadeIn('slow');
});
return false;
}
})
.data( "autocomplete" )._renderItem = function( ul, item ) {
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a>" + item.label + "<br>" + item.desc + "</a>" )
.appendTo( ul );
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question