Control: Textbox with autosuggest

 Show all Hide all

Shows a textbox. When the user types in the textbox a list of suggestions is shown. The user can choose one suggestion from the list or continue writing. The control accepts values not in the list of suggestions.

Start value:
Return value: The text from the textbox.

Control container: NewEdit

Supported in: NewEdit Parameter page Multirow

SQL

SQL Call: Get suggestions (mandatory)

This call is made repeatedly as the user types into the textbox, and returns a list of suggestions that can autocomplete to the typed value.

To make the control have the proper responsiveness it is imperative that the procedure returns quickly, preferably in less than 100 ms.
Supports custom errors: No
May modify database: No

Parameters:

@TopN mandatory int
Max number of suggestions to return. For better performance it is necessary to limit the number of suggestions sent from the database to the client.

Always use the exact value of @TopN in the TOP-clause. Returning more values will cause an immediate exception. Returning fewer values when more values are present can cause unpredictable behavior.
@Value mandatory string
The text entered into the textbox. All returned suggestions must start with this string.

Resultset: Suggestions

The suggestions to autocomplete.
Repeat mode: repeated exactly once
Row count: zero or more rows

Columns:

<column with ordinal 1> mandatory string
Text to autocomplete the textbox with. Must start with @Value. Values must be distinct.
<column with ordinal 2> optional string
Text displayed in the suggestion list. Use if you need to include some extra information together with the suggestion.
If not present the values from the first column are used, and the values in the suggestion list are exactly the values that will be autocompleted.

Default value

SQL Call: Default value

Retrieves the default value for the control.
Supports custom errors: No
May modify database: No

Resultset: Default value

Repeat mode: repeated exactly once
Row count: exactly one row

Columns:

<column with ordinal 1> mandatory string
The default value

Validation

SQL Call: Validation

Performs field validation when the user leaves the field or one of its dependencies is changed. This call is only made if there is a field validation of type SQL set for the field info.
Supports custom errors: No
May modify database: No

Parameters:

@Value mandatory string
The value of the field, the procedure will not be called if value is NULL.

Resultset: Validation messages

Repeat mode: repeated zero or one time
Row count: zero or one row

Columns:

Error optional string
Error message to display. Blocks the user from saving.
Info optional string
Informative message to display. Does not block saving.

Examples

Textbox With Autosuggest

"Textbox with autosuggest" works like a "textbox with dropdown" because it allows any text to be entered, even if it's not included in the list. But it also works like a "textbox with popup" as it continously searches a stored procedure for suggestions. The ”Auto” part is that the popup is opened automatically as you type and not on "tab".

The Control is best suited to autocompleating of names and search Words. If you want to replace a "textbow with popup", then you should use "textbox with autosearch" instead.

CREATE PROCEDURE Example.TextboxWithAutosuggestTable_TextboxWithAutosuggest
	@TopN int = 7,
	@Value varchar(max)
AS
BEGIN

	-- You have to use the escape function below, or else the control will crash if you search for %, [], [^] and _
	SELECT @Value = SoftadminUtil.String_EscapeLikeWildcards(@Value); 
	
	SELECT DISTINCT TOP (@TopN)
		T.TextboxWithAutosuggestTableName
	FROM
		(
			VALUES
				(1, 'alpha'),
				(2, 'beta'),
				(3, 'gamma'),
				(4, 'delta')
		) AS T (TextboxWithAutosuggestTableId, TextboxWithAutosuggestTableName) 
	WHERE
		T.TextboxWithAutosuggestTableName LIKE ISNULL(@Value, '') + '%';
END;

Best practice

Escape @Value

Always escape searched value.
SELECT @Value = SoftadminUtil.String_EscapeLikeWildcards(@Value);