0

I am trying to figure out how to make a title column of a document library search a list. The Title column of the document library in this application is called "vendor name". What I want to happen, is for the user to have a dynamic dropdown list like google. If the user types in "s", the title field should look at the "vendor list" for names of vendors that contain the letter s, and create a dropdown filled with those names. We have to many vendors to make a normal dropdown list work, so I wanted to add a filtering capability to the dropdown. Is there any way to do this?

Edit: For those who wanted the code... This is working on a content editor, but I can't figure out how to make it work on the title column of a list..

     <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
     <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.min.js"></script>
       <script>

       // A $( document ).ready() block.
       var availableTags = [];
     $( document ).ready(function() {


           $().SPServices({
     operation: "GetListItems",
     async: false,
     listName: "VendorName", // or list name.
     CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
     CAMLQuery: "<Query></Query>",
completefunc: function (xData, Status){
    $(xData.responseXML).SPFilterNode("z:row").each(function(){
        var title =$(this).attr("ows_Title");
        availableTags.push(title);
    });     
}
  });

     });

       $( function() {
         $( "#tags" ).autocomplete({
           source: availableTags
         });
       } );
       </script>

     <div class="ui-widget">
       <label for="tags">Vendor Name: </label>
       <input id="tags">
     </div>
2
  • there should be plenty of examples around using jquery autocomplete Commented Dec 13, 2016 at 21:39
  • Jquery autocomplete, thats what I was looking for. I wasn't sure what to search, thank you Commented Dec 13, 2016 at 21:40

1 Answer 1

0

Putting answer here with code for others.

In below example your need to initialize array availableTags with title(Vendar Name) column of your document library. Use CSOM to get items from documents and add title to array availableTags

  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>

  // A $( document ).ready() block.
$( document ).ready(function() {
var availableTags = [];

      $().SPServices({
operation: "GetListItems",
async: false,
listName: {list guid}, // or list name.
CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
CAMLQuery: "<Query>Query>",
    completefunc: function (xData, Status){
        $(xData.responseXML).SPFilterNode("z:row").each(function(){
            var title =$(this).attr("ows_Title");
            availableTags.push(title);
        });     
    }
      });

});

  $( function() {
    $( "#tags" ).autocomplete({
      source: availableTags
    });
  } );
  </script>

<div class="ui-widget">
  <label for="tags">Vendor Name: </label>
  <input id="tags">
</div>

For diffrent autocomplete options ref link

3
  • How can I make this work on a column in a list, instead of in a content editor? Commented Dec 15, 2016 at 20:42
  • @sabien...it is working on columns only in any type of list, content editor is just a to inject script in your new/edit form. Commented Dec 16, 2016 at 2:57
  • So to make the script run in quick edit mode of a doclib(on the title column), how should I add the code? in a content editor on the allItems.aspx page? I explained the issue with that here: sharepoint.stackexchange.com/questions/202694/… Commented Dec 16, 2016 at 18:03

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.