V
V
Valeriy19972015-09-01 10:15:49
JavaScript
Valeriy1997, 2015-09-01 10:15:49

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 );
        };


Here is the version with the included library: jsfiddle.net/t52ka/35

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
eldar_web, 2015-09-01
@Valeriy1997

Instead of the plugin content, put this content: code.jquery.com/ui/1.11.4/jquery-ui.js
That is, you should also mark that initialization code inside the jquery function. In short, here: jsfiddle.net/t52ka/36

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question