How to show search suggestions in a text field during typing

Questions, tips and tricks and techniques for scripting in Servoy

How to show search suggestions in a text field during typing

Postby deezzub » Mon Jun 03, 2013 3:15 pm

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.
Last edited by deezzub on Fri Jun 13, 2014 10:21 am, edited 1 time in total.
deezzub
 
Posts: 328
Joined: Tue May 28, 2013 3:02 pm
Location: Oldenburg, Germany

Re: How to show search suggestions in a text field

Postby Joas » Mon Jun 03, 2013 3:50 pm

Change your valuelist so it is based on a global method, in that method you can implement it however you want.
Joas de Haan
Yield Software Development
Need help on your project? yieldsd.com
User avatar
Joas
Site Admin
 
Posts: 842
Joined: Mon Mar 20, 2006 4:07 pm
Location: Leusden, NL

Re: How to show search suggestions in a text field

Postby peterbliskavka » Mon Jun 03, 2013 3:52 pm

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;
}
peterbliskavka
 
Posts: 30
Joined: Tue May 21, 2013 3:42 pm

Re: How to show search suggestions in a text field

Postby deezzub » Tue Jun 04, 2013 12:08 pm

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?
deezzub
 
Posts: 328
Joined: Tue May 28, 2013 3:02 pm
Location: Oldenburg, Germany

Re: How to show search suggestions in a text field

Postby peterbliskavka » Tue Jun 04, 2013 4:24 pm

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.
peterbliskavka
 
Posts: 30
Joined: Tue May 21, 2013 3:42 pm


Return to Methods

Who is online

Users browsing this forum: No registered users and 7 guests