2

I have loaded my Autocomplete combobox script from: http://jqueryui.com/demos/autocomplete/#combobox and it appears with my list.

Below it, I have a list that works just fine using:

  • function processResult(xData, status) { $(xData.responseXML).find("List").each(function() { $("#data").append( + $(this).attr("Title") +); }); }
  • Thanks to Jan Tielens Bloggings: http://weblogs.asp.net/jan/archive/2009/04/09/calling-the-sharepoint-web-services-with-jquery.aspx

    How do I get the list to actually filter once something is selected? I assume its in the $(this).attr() but nothing seems to work.

    Apologies in advance for the DAY1 Newbie question.

    Thanks

    2
    • 2
      Have a look at SPServices for communicating with SharePoint webservices using jQuery/javascript: spservices.codeplex.com Commented Mar 7, 2011 at 20:25
    • Can you elaborat e on how you plan on using this? Are you writing a custom web part? Are you using adataview web part, list view, etc.. Commented Mar 8, 2011 at 2:09

    2 Answers 2

    3

    Use SPServices and use the select option in autocomplete:

    <link href="../css/jquery-ui.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/jquery-ui.js"></script>
    <script type="text/javascript" src="../js/jquery.SPServices-0.5.8.js"></script>
    
    <script type="text/javascript">
    $(document).ready (function() {
        $().SPServices({
            operation: "GetListItems",
            async: true,
            listName: "Resources",
            CAMLViewFields: "<ViewFields>" +
                "<FieldRef Name='Title' />" +
                "<FieldRef Name='resource_link' />" +
                "<FieldRef Name='image_url' />" +
                "</ViewFields>",
            completefunc: AttachAutoComplete
        });
    
        function AttachAutoComplete(xmlResponse) {
            var domElementArray = $( "[nodeName=z:row]", xmlResponse.responseXML );
    
            var dataMap = domElementArray.map(function() {
                return {
                    value: $(this).attr('ows_Title'),
                    url: $(this).attr('ows_resource_link'),
                    image_url: $(this).attr('ows_image_url')
                };
            });
    
            var data = dataMap.get();
    
            $("input#inputAutoComplete").autocomplete({
                source: data,
                formatItem: function(row){
                    if(row){
                        return "<table><tr><td><img src=\"" + row.image_url + "\" border=\"0\" /></td><td>"+ row.value + " 55</td></tr></table>";
                    }
                },
                select: function(e, ui){
                    window.open(ui.item['url']);
                }
            });
        }
    </script>
    
    Sign up to request clarification or add additional context in comments.

    4 Comments

    This is great!!! if I add: $("#tasksUL").empty(); The drop down list will refresh when I select the autocomplete again.
    .html("") works too... :o) But I would stick with what you have.
    And since you are new to STACK OVERFLOW... You should accept answers. This helps show they are answered and helps you and others get deserved reputation points which also allows users to have more options and resources on the site. Have fun.
    Also, @MD, you may have to write your own formatItem function. Im not sure the autocomplete from SPServices supports it. But having it wont break it.
    1

    You can fire an onkeyup even if you are using a standard input. It would look something like:

    <input type="text" name="search" id="txtSearch" onkeyup="searchOpen()" />
    

    Comments

    Your Answer

    By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.