Skip to main content

AutoComplete

Properties

PropertyTypeOptionalDescription
optionstableNoOptions to select from in the autocomplete
defaultValuestringYesInitial selected option
placeholderstringYesPlaceholder of the input
allowClearbooleanYesWeather to show clear button
autoFocusbooleanYesWill give the autocomplete focus when focused
backfillbooleanYesMakes the autocomplete controllable with the keyboard
borderedbooleanYesWeather the autocomplete has a border
defaultOpenbooleanYesInitial open state of dropdown
disabledbooleanYesWeather the autocomplete is disabled
notFoundContentstringYesContent to display when to match is found
statuserror, warningYesValidation status
onBlurfunction()YesCalled when leaving the component
onChangefunction(string)YesCalled when input changes
onDropdownVisibleChangefunction(boolean)YesCalled when dropdown opens/closes
onFocusfunction()YesCalled when entering the component
onSearchfunction(string)YesCalled when searching items
onSelectfunction(value, option)YesCalled when a option is clicked
onClearfunction()YesCalled when clear button is clicked

See more properties here.

Children

AutoComplete does not support children.

Example

local options = {
{
value = "Option 1"
},
{
value = "Option 2"
},
{
label = "Label",
value = "Some text"
},
{
value = "Xean"
},
{
value = "Walter"
},
}

local autoComplete = AM:createElement("AutoComplete", {
placeholder = "Input Here!",
width = "175px",
options = options,
allowClear = true,
onBlur = function(id, name)
print("onBlur: ", id, name)
end,
onChange = function(id, name, value)
print("onChange: ", id, name, value)
end,
onDropdownVisibleChange = function(id, name, open)
print("onDropdownVisibleChange: ", id, name, json.encode(open))
end,
onFocus = function(id, name)
print("onFocus: ", id, name)
end,
onSearch = function(id, name, value)
print("onSearch: ", id, name, value)
end,
onSelect = function(id, name, value, option)
print("onSelect: ", id, name, value, json.encode(option))
end,
onClear = function(id, name)
print("onClear: ", id, name)
end,
})

This is how it looks in-game:

In Game

Options

Options are the values it will autocomplete to.

Properties
PropertyTypeOptionalDescription
valuestringNoValue of the option
labelstringYesLabel of the option, will be shown over value

Default Value

Is the value already written in the input when the UI is initialized.

Placeholder

Is the text shown within the input, when there is nothing written by a user.

placeholder = "Input Here!"

Placeholder

Allow Clear

When true a "x" is shown, when it's pressed will clear the users input.

Allow Clear

Auto Focus

When true the AutoComplete will be focused when shown.

Backfill

Allows the user to use the keyboard to select options.

Bordered

Weather the AutoComplete should have a border.

Bordered

DefaultOpen

When true the popup of the AutoComplete will be shown by default.

Disabled

When true the AutoComplete will be disabled.

Disabled

NotFoundContent

Is the text shown when the user inputs something that is not in options.

NotFoundContent

Status

When set the outline of the input will change depending on its value.

Status

OnBlur

Event is fired when the user clicks away from the input.

onBlur = function(id, name)
print("User Clicked Away From Autocomplete.")
end

OnChange

Event is fires when the user changes the input.

onChange = function(id, name, value)
print("Changed Input To: " .. value)
end

So if the user wrote a it will print Changed Input To: a

OnDropdownVisibleChange

Event fires when the popup/suggestion list is shown/hidden.

onDropdownVisibleChange = function(id, name, open)
local str = "Opened"
if not open then
str = "Closed"
end
print("User " .. str .. " the input popup.")
end

OnFocus

Event fires when the user presses the input to write.

onFocus = function(id, name)
print("User Focused the Input.")
end

OnSearch

"Called when searching items"

Seems to be the same as OnChange

OnSelect

Event fires when the user presses a suggestion from the list.

onSelect = function(id, name, value, option)
print("User Selected: " .. value)
print("Options: " .. json.encode(option))
end

OnClear

Event is fired when the user presses the clear button.

Which is only shown when Allow Clear is true.

onClear = function(id, name)
print("User Cleared the Input")
end