# How to show search suggestions in a text field during typing

**URL:** <https://forum.servoy.com/t/how-to-show-search-suggestions-in-a-text-field-during-typing/17249>\
**Category:** Classic Servoy\
**Created:** [June 3, 2013, 1:15pm UTC](https://forum.servoy.com/t/how-to-show-search-suggestions-in-a-text-field-during-typing/17249 "2013-06-03T13:15:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![deezzub](https://avatars.discourse-cdn.com/v4/letter/d/dec6dc/32.png) [@deezzub](https://forum.servoy.com/u/deezzub)\
**Post date:** [June 3, 2013, 1:15pm UTC](https://forum.servoy.com/t/how-to-show-search-suggestions-in-a-text-field-during-typing/17249/1 "2013-06-03T13:15:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Joas](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/joas/32/5095_2.png) [@Joas](https://forum.servoy.com/u/Joas)\
**Post date:** [June 3, 2013, 1:50pm UTC](https://forum.servoy.com/t/how-to-show-search-suggestions-in-a-text-field-during-typing/17249/2 "2013-06-03T13:50:41Z")

</div>

Change your valuelist so it is based on a global method, in that method you can implement it however you want.

---

<div class="post-metadata">

**Author:** ![peterbliskavka](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@peterbliskavka](https://forum.servoy.com/u/peterbliskavka)\
**Post date:** [June 3, 2013, 1:52pm UTC](https://forum.servoy.com/t/how-to-show-search-suggestions-in-a-text-field-during-typing/17249/3 "2013-06-03T13:52:40Z")

</div>

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:

```auto
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;
}

```

---

<div class="post-metadata">

**Author:** ![deezzub](https://avatars.discourse-cdn.com/v4/letter/d/dec6dc/32.png) [@deezzub](https://forum.servoy.com/u/deezzub)\
**Post date:** [June 4, 2013, 10:08am UTC](https://forum.servoy.com/t/how-to-show-search-suggestions-in-a-text-field-during-typing/17249/4 "2013-06-04T10:08:08Z")

</div>

> Joas:  
> 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. ![;)]( "Wink")

> 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:
> 
> ```auto
> 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;

```

}

> ```auto
> 
> ```

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

---

<div class="post-metadata">

**Author:** ![peterbliskavka](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@peterbliskavka](https://forum.servoy.com/u/peterbliskavka)\
**Post date:** [June 4, 2013, 2:24pm UTC](https://forum.servoy.com/t/how-to-show-search-suggestions-in-a-text-field-during-typing/17249/5 "2013-06-04T14:24:23Z")

</div>

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.
