Autocomplete possible with Forms Designer?

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
thebrightlord
Posts: 12
Joined: Wed Nov 13, 2019

19 Mar 2020

Looked through the documentation, did not find anything.

Does Forms Designer have any custom methods or support autocomplete fields on custom forms? By this I mean typing in a few letters then having the field "suggest" values from somewhere, similar to how google does it.

User avatar
mnikitina
Posts: 264
Joined: Wed Jun 05, 2019

19 Mar 2020

Hello thebrightlord,

Forms Designer doesn't have a built-in autocomplete function. But you can adapt the code from this example for Forms Designer:

thebrightlord
Posts: 12
Joined: Wed Nov 13, 2019

21 Apr 2020

I was able to get this working. Not on the forms designer fields but on raw html inputs such as textboxes. All you have to do is attach the autocomplete functionality to those like below, then port over the information using javascript to copy the needed information into the forms designer fields for display/manipulation purposes.

Code: Select all

  $(".title").autocomplete({
   minLength: 1,
  source: function (request, response) {
  var term = request.term;
  
  var spUrl = "URL HERE";
  var restUrl = spUrl + "/_api/Web/Lists/getbytitle('Sport')/items?$filter=substringof('" + term + "',Info)";
  
   $.ajax({
      contentType : "application/json;odata=verbose",
 headers : { "accept" : "application/json;odata=verbose" },
  url: restUrl,
  dataType: 'json',
  success: function(data){          
  response($.map(data.d.results, function (value, key) {
  return {
    label: value.Title,
   value: value.Title,
         };
 }));    
   }
  });
 }

});
The code here uses the SharePoint REST api to make a call to the 'Sport' list at the URL HERE location on the textbox with a class named 'title' and is filtering the 'Info' column based on what you type.

The minimum length represents the amount of text typed before the AJAX call is made.

The return code controls what gets returned, that can be edited to fill in other fields simultaneously though its a bit more involved than that, unique names have to be created if you want to return those values and set other fields once returned (e.g. if you want the modified date, it would be modified: value.Modified, and ID would be id: value.ID). Whatever the column name is, it'd be value.columnname with a custom designation in front basically.

This was a good site, with examples of how to use autocomplete, though not SharePoint specific: https://jqueryui.com/autocomplete/
Here is how to use the REST api to filter, sort and much more: https://social.technet.microsoft.com/wi ... -list.aspx

Its quite powerful.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 9 guests