[ 3 posts ]

Patrick Ouellette

  • Username: hendross
  • Joined: Tue Feb 14, 2012 8:36 am
  • Posts: 10
  • Offline
  • Profile

Autocomplete DataSource Duplicates

Post Posted: Tue Feb 14, 2012 8:54 am
+0-
I have a DataSource which contains duplicate revised values like;
Code:
{"ResultSet":{
      "Result":[
{"original":"5MAIL.COM","revised":"GMAIL.COM"},
{"original":"8MAIL.COM","revised":"GMAIL.COM"},
{"original":"A0L.COM","revised":"AOL.COM"},
{"original":"AAOL.COM","revised":"AOL.COM"}
...

I'm using it in a DataTable AND AutoComplete widget
Code:
   
Y.one('#revised').plug(Y.Plugin.AutoComplete, {
     requestTemplate: '',
     resultTextLocator: 'revised',
     resultFilters: 'startsWith',
     resultHighlighter: 'startsWith',
     source: dataSource
});

However, there are duplicate results in the dropdown, what/where is the best way to only select DISTINCT revised values from the oDS?

Scott Jungling

YUI Contributor

  • Username: sjungling
  • Joined: Fri Oct 09, 2009 8:44 am
  • Posts: 9
  • Location: Chico, CA
  • Twitter: sjungling
  • GitHub: sjungling
  • Gists: sjungling
  • IRC: sjungling
  • Offline
  • Profile

Re: Autocomplete DataSource Duplicates

Post Posted: Fri Jun 01, 2012 8:47 pm
+0-
This might not be a drop-in solution, but you can use the Y.Array utilities to take an array (ResultSet.Result) and pluck out all of 'revised' values and then pass that through the Y.Array.dedupe method to generate an unique array.

Code:
   
YUI().use('collection', function(Y) {
       var src = {
          "ResultSet": {
             "Result": [{
                "original": "5MAIL.COM",
                "revised": "GMAIL.COM"
             },
             {
                "original": "8MAIL.COM",
                "revised": "GMAIL.COM"
             },
             {
                "original": "A0L.COM",
                "revised": "AOL.COM"
             },
             {
                "original": "AAOL.COM",
                "revised": "AOL.COM"
             }]
          }
       };
       var results = Y.Array(src.ResultSet.Result);
       var allResult = results.map(function(item) {
          return item.revised;
       });
       var uniqResults = Y.Array.dedupe(allResult);
       Y.log(uniqResults);
    });

Todd Smith

YUI Contributor

  • Username: stlsmiths
  • Joined: Thu Nov 05, 2009 10:03 am
  • Posts: 675
  • GitHub: stlsmiths
  • Gists: stlsmiths
  • IRC: t_smith
  • Offline
  • Profile

Re: Autocomplete DataSource Duplicates

Post Posted: Sun Jun 03, 2012 4:22 pm
+0-
Patrick,

Recommend you look into the Custom resultFilter for Autocomplete, specifically AutoComplete User Guide - Writing Results Filters.

You would define a function to filter the results, and could incorporate sjungling's approach or your own very easily.

Todd
  [ 3 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum