question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Autocomplete editor doesn't work when specifying label/values and custom search function

See original GitHub issue

Is your feature request related to a problem? Please describe. Autocomplete editor does not work when specifying display labels that are different than the value you want to store, i.e.

{title:"Name", field:"name", editor:"autocomplete", editorParams:{
    values:{
        "steve":"Steve Boberson",
        "bob":"Bob Jimmerson",
        "jim":"Jim Stevenson",
    }
}}

and specifying a custom searchFunc:

    searchFunc:function(term, values){ //search for exact matches
        var matches = []

        values.forEach(function(item){
            if(item.value === term){
                matches.push(item);
            }
        });

        return matches;
    },

Describe the solution you’d like When using both searchFunc and the object key/value pair for different label values, I would like to be able to return the same object key/value pair structure as specified in the values propery

Describe alternatives you’ve considered I have tried returning an object with matching key/value pairs from the searchFunc as initially sent to the values property, and returning just an array of the matching keys, neither works

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
olifolkerdcommented, Apr 6, 2019

Hey All,

So the issue relates specifically to when the searchFunc was being used, it wasn’t consistently handling the results from the different types of the values passed into the values property.

I have tweaked the way the function operates, regardless of the type of input the searchFunc function will be passed in an array of search item objects with the format:

{
    title:"Steve", the title shown in the list
    value:"steve", the value of the item
}

The function must now return an array of these objects that match your search criteria, (these must be the same objects passed in to the function, you cannot rebuild them or it will break the references)

so an example search function that does a strict comparison would be:

searchFunc: function(term, allItems){
    var matches = [];

    allItems.forEach(function(item){
        if(item.value == term){
            matches.push(item);
        }
    });

    return matches;
},

I will include these changes in the 4.2.4 patch release later this weekend and update the documentation to match.

Cheers

Oli 😃

1reaction
dseilercommented, Apr 6, 2019

I have noticed a similar issue when trying to use custom searchFunc with autocomplete editor like this:

{ title: "Epic", field: "epic", editor:"autocomplete", editorParams: {
              showListOnEmpty: true,
              freetext: true,
              allowEmpty: true,
              searchFunc: function(term, allItems){
                  console.log(allItems);
                  var matches = [];

                  allItems.forEach(function(item){
                      if(item.value === term){
                          matches.push(item);
                      }
                  });

                  return matches;
              },
              values: ["Accounts", "Products", "Quotation"], //array of possible values
            }
          },

When running this I always get the following exception:

tabulator.min.js:7 Uncaught TypeError: Cannot create property ‘element’ on string ‘Accounts’ at tabulator.min.js:7 at Array.forEach (<anonymous>) at l (tabulator.min.js:7) at a (tabulator.min.js:7) at HTMLInputElement.<anonymous> (tabulator.min.js:7) at tabulator.min.js:7 at w.edit (tabulator.min.js:6) at HTMLDivElement.<anonymous> (tabulator.min.js:6)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issue with custom properties in jQuery UI Autocomplete
The issue is that there are no label and value properties specified, so by default autocomplete tries to search the text box value...
Read more >
Populating autocomplete with Sources - Algolia
Autocomplete lets you fetch from different sources and display different types of results that serve different purposes.
Read more >
_renderItem for jquery Autocomplete doesn´t work ...
Hello i would made an Autocomplete function for an intern order form. ... Autocomplete recognizes "label" as the key for the values you...
Read more >
Building an accessible autocomplete control - Adam Silver
Unfortunately, native HTML form controls just aren't good enough for this type of interaction. And so we need to build a custom autocomplete...
Read more >
Lightweight Autocomplete Controls with the HTML5 Datalist
Too many options in your HTML Select list? Try a Datalist! Learn how to work with this lightweight, accessible, cross-browser autocomplete ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found