Page 1 of 1

How to show search suggestions in a text field during typing

PostPosted: Mon Jun 03, 2013 3:15 pm
by deezzub
How to show search suggestions in a text field during typing? I tried a field using the property "displayType" "TYPE_AHEAD" and then I applied a valuelist with table values "name" from a database. This only works for the beginning character. If I want to search for a string "n.v." that is not the beginning of a word, this doesn't work.

Re: How to show search suggestions in a text field

PostPosted: Mon Jun 03, 2013 3:50 pm
by Joas
Change your valuelist so it is based on a global method, in that method you can implement it however you want.

Re: How to show search suggestions in a text field

PostPosted: Mon Jun 03, 2013 3:52 pm
by peterbliskavka
The way I was able to do this was by attaching a global method to the valuelist. Here is a sample in which I split the search string on spaces:

Code: Select all
function getDataSetForValueList_vlUserManagement_username(displayValue, realValue) {
   /**@type {JSFoundSet<db:/sample/table_one>} */
   var fs = databaseManager.getFoundSet('db:/sample/table_one');
   /** @type  {JSDataSet} */
   var result = null;
   if (displayValue == null && realValue == null) {//field is empty
      fs.loadAllRecords();
      fs.sort('column_one asc')
      result = databaseManager.convertToDataSet(fs,['column_one','column_two']); //[display value, real value]
   } else if (displayValue != null) {//field has text
      var searchText = utils.stringTrim(displayValue);
      var searchArray = searchText.split(' ');
      if (fs.find()) {
         fs.column_one = '%' + searchArray[0] + '%';
         fs.search();
         for (var a = 1; a < searchArray.length; a++) {
            if (fs.find()) {
               fs.column_one = '%' + searchArray[a] + '%';
               fs.search(false, true);
            }
         }
      }
      fs.sort('column_one asc');
      result = databaseManager.convertToDataSet(fs,['column_one','column_two']);
   }
   return result;
}

Re: How to show search suggestions in a text field

PostPosted: Tue Jun 04, 2013 12:08 pm
by deezzub
Joas wrote:Change your valuelist so it is based on a global method, in that method you can implement it however you want.


My intention was, how can I do it in the global method. ;)

peterbliskavka wrote:The way I was able to do this was by attaching a global method to the valuelist. Here is a sample in which I split the search string on spaces:

Code: Select all
function getDataSetForValueList_vlUserManagement_username(displayValue, realValue) {
   /**@type {JSFoundSet<db:/sample/table_one>} */
   var fs = databaseManager.getFoundSet('db:/sample/table_one');
   /** @type  {JSDataSet} */
   var result = null;
   if (displayValue == null && realValue == null) {//field is empty
      fs.loadAllRecords();
      fs.sort('column_one asc')
      result = databaseManager.convertToDataSet(fs,['column_one','column_two']); //[display value, real value]
   } else if (displayValue != null) {//field has text
      var searchText = utils.stringTrim(displayValue);
      var searchArray = searchText.split(' ');
      if (fs.find()) {
         fs.column_one = '%' + searchArray[0] + '%';
         fs.search();
         for (var a = 1; a < searchArray.length; a++) {
            if (fs.find()) {
               fs.column_one = '%' + searchArray[a] + '%';
               fs.search(false, true);
            }
         }
      }
      fs.sort('column_one asc');
      result = databaseManager.convertToDataSet(fs,['column_one','column_two']);
   }
   return result;
}


Thanks, that was what I needed, but what is the "realValue" for?

Re: How to show search suggestions in a text field

PostPosted: Tue Jun 04, 2013 4:24 pm
by peterbliskavka
When you create a valuelist, there is the option for "Show in field / list" and "Return in dataprovider". "Show in field / list" is the displayValue, "Return in dataprovider" is the realValue. They can be the same column, but in my case I am using a string column for the display value and a UUID column for the realValue.