You should avoid using Textbox with popup for new development, and try to migrate existing uses of it to Textbox with Autosearch.
The control type Textbox with autosearch is recommended instead of Textbox with popup.
Lets the user search for possible values by entering search phrases into a textbox. The search is performed when the user leaves the control either using the mouse or using the tab-key. The search can result in one of four scenarios:
There is only one match for the search phrase, in which case that one hit becomes the active selection and focus is moved to the next control.
There is no match to the search phrase, in which case the previously active selection is restored to the text and focus is retained so the user can perform a new search.
There is more than one match to the search phrase, in which case a list of possible matches is displayed and the user has to choose one of them before moving on to the next control.
An error occurs during the search, in which case an error message can be shown to the user.
Textbox with popup in its initial state.
The user can type in the textbox.
But when the control loses focus (the user presses tab or clicks the mouse), a list opens that is filtered by the text typed.
The user has to select an item in the list, or otherwise the textbox will be cleared, since the textbox with popup will not allow arbritrary text.
Used when initializing control to determine the textbox value belonging to the supplied id.
SQL-statement that fills the popup-control with possible values.
Retrieves the default value for the control.
This call is only made if there is a field validation set for the field info and the field has any content.
Performs field validation when the user leaves the field or one of its dependencies is changed, initial values set by default value and initial values in edit-mode are not validated.
When saving the validation runs server side if the field value has changed. A field value is considered changed if in new mode the value is anything other than NULL
. In edit mode it is considered changed if it has a value that was not returned by the GetEditFields procedure.
Since Softadmin 6.0-ish you only have to handle two cases. Lookup and popup.
The tool tip is only displayed if tool tip is enabled in "Edit field info".
The search is limited to 50 matches since more matches would take a long time to load and having such a large result would not be user friendly.
CREATE PROCEDURE Example.TextboxWithPopupTable_TextboxWithPopup
@Id int = NULL,
@Value varchar(300) = NULL
AS
BEGIN
----------------------------------------------------------------------
-- Look up the displayed value in the textbox for an existing value --
----------------------------------------------------------------------
IF @Id IS NOT NULL
BEGIN
SELECT
T.TextboxWithPopupTableName
FROM
(
VALUES
(1, 'alpha'),
(2, 'beta'),
(3, 'gamma'),
(4, 'delta')
) AS T (TextboxWithPopupTableId, TextboxWithPopupTableName)
WHERE
T.TextboxWithPopupTableId = @Id;
RETURN;
END;
---------------------------------------------------
-- Retrieve entries matching the search criteria --
---------------------------------------------------
SELECT @Value = SoftadminUtil.String_EscapeLikeWildcards(@Value);
CREATE TABLE #Results
(
Id int, -- Id value that will be sent to the InsertUpdate procedure
TextboxValue varchar(300), -- Text to be displayed for the selected entry in the textbox
ListboxValue varchar(300), -- Text shown in the listbox containing matches
Tooltip varchar(300) -- Tooltip displayed for entries in the listbox
);
INSERT INTO #Results
(
Id,
TextboxValue,
ListboxValue,
Tooltip
)
-- Limit to no more than 50 matches to avoid slowing down the newedit page and making the user wait
SELECT TOP 50
T.TextboxWithPopupTableId,
'Textbox: ' + T.TextboxWithPopupTableName AS [TextboxValue],
'Listbox: ' + T.TextboxWithPopupTableName AS [ListboxValue],
'Tooltip: ' + T.TextboxWithPopupTableName AS [Tooltip]
FROM
(
VALUES
(1, 'alpha'),
(2, 'beta'),
(3, 'gamma'),
(4, 'delta')
) AS T (TextboxWithPopupTableId, TextboxWithPopupTableName)
WHERE
-- Retrieve entries whose name matches the search text
T.TextboxWithPopupTableName LIKE '%' + @Value + '%'
ORDER BY
[ListboxValue];
------------------------------
-- Send data to the control --
------------------------------
SELECT
R.Id,
R.TextboxValue,
R.ListboxValue,
R.Tooltip
FROM
#Results R
ORDER BY
R.ListboxValue;
--------------
-- Clean up --
--------------
DROP TABLE #Results;
END;
For stable and predictable behaviour, always use an explicit ORDER BY clause.
Always limit the number of hits by using TOP 50 or another number that is appropriate for the situation. The reason for this is that large number of results are not very user friendly and also that they take a very long time to display.
The name depends on the usage. If the control is used to retrieve values from a lookup table then the procedure should be named "<Schema>.<LookupTable>TextboxWithPopup". If it is not and the values are not directly linked to rows in a table or the functionality is specific for the current field (say for instance when you want to exclude already connected entries) then the procedure should be named "<Schema>.<Table><Field>_TextboxWithPopup".
Make sure to handle a value of NULL in the parameter @Value. If you don't the user won't be able to clear the textbox by doing a search using an empty value.
Escape searched value.
SELECT @Value = SoftadminUtil.String_EscapeLikeWildcards(@Value);