esx_menu_dialog
esx_menu_dialog reference for ESX Legacy. Ask players for a text or number value with ESX.UI.Menu.Open('dialog'), data fields, callbacks and input rules.
esx_menu_dialog is the input box of ESX Legacy. It shows a title, one text field
(or a larger text area) and Submit/Cancel buttons. Use it when you need a
single value from the player, such as an amount of money, a plate or a short
message. You open it with ESX.UI.Menu.Open('dialog', ...).
Overview
| Resource | esx_menu_dialog |
| Side | Client only |
| Menu type | dialog |
| Dependencies | es_extended, esx_lib (loaded via @esx_lib/imports.lua) |
| UI | jQuery + Mustache page in html/ |
The resource has no configuration file. The dialog takes mouse and keyboard focus about 200 ms after opening and releases it when the last dialog closes.
The manifest only lists es_extended, but the client loads
@esx_lib/imports.lua. Start esx_lib first.
Opening a dialog
ESX.UI.Menu.Open('dialog', namespace, name, data, submit, cancel, change, close)| Name | Type | Description |
|---|---|---|
namespace | string | Usually GetCurrentResourceName(). |
name | string | Unique dialog name inside the namespace. |
data | table | Dialog data, see below. |
submit | function(data, menu)? | Submit button or Enter. |
cancel | function(data, menu)? | Cancel button or Escape. |
change | function(data, menu)? | Runs on every keystroke with the current text in data.value. |
close | function()? | Runs after menu.close(). |
The returned menu object and the generic helpers (ESX.UI.Menu.Close,
CloseAll, IsOpen) are documented on the
esx_menu_default page.
Dialog data
| Field | Type | Description |
|---|---|---|
title | string | Text in the header. Escaped, so HTML is shown as text. |
type | string? | 'default' (single-line input, default) or 'big' (multi-line text area). |
value | string? | Prefilled value. |
Callback data
| Field | Description |
|---|---|
data.value | What the player typed. On submit it is always a string. |
data.title, data.type | Copied from your dialog data. |
data._namespace, data._name | Menu identifiers. |
Input rules on submit
Before your submit callback runs, the resource processes the value:
- If the text parses as a number, it is rounded to the nearest integer.
- If that number is
0or negative, the dialog shows the notification "That input is not allowed!" and does not callsubmit. - The value is trimmed and converted to a string.
So " 12.6 " arrives as "13", "-5" and "0" never arrive, and text like
"ABC 123" passes through trimmed.
Example
local function askDepositAmount()
ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'bank_deposit', {
title = 'Deposit amount',
}, function(data, menu)
local amount = tonumber(data.value)
if not amount then
ESX.ShowNotification('Enter a valid number', 'error')
return
end
menu.close()
TriggerServerEvent('my_bank:deposit', amount)
end, function(data, menu)
menu.close()
end)
endA multi-line dialog with a prefilled value:
ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'edit_note', {
title = 'Note',
type = 'big',
value = currentNote,
}, function(data, menu)
menu.close()
TriggerServerEvent('my_notes:save', data.value)
end, function(data, menu)
menu.close()
end)Validate on the server
The rounding and the positive-number check run on the client. A cheater can trigger your server event with any value, so check the amount again on the server.
Controls
| Key | Action |
|---|---|
| Enter | Submit |
| Escape | Cancel |
| Mouse | Submit / Cancel buttons |
Common issues
- Comparing
data.valueto a number fails: it is a string. Usetonumber(data.value). - Players cannot enter
0: by design. If you need zero or negative values, read them in achangecallback or use esx_context number inputs. - Dialog stays open after Submit: call
menu.close()insubmitandcancel. - Mouse cursor stays after closing: focus is only released when no dialog
is left open. Make sure every dialog you open is closed, or call
ESX.UI.Menu.CloseAll().
Related
Frequently asked questions
Independent documentation
Last updated on
esx_menu_default
esx_menu_default reference for ESX Legacy. Build keyboard list menus with ESX.UI.Menu.Open, sliders, element fields, menu methods, keybinds and fixes.
esx_menu_list
esx_menu_list reference for ESX Legacy. Show table menus with clickable row buttons via ESX.UI.Menu.Open('list'), the head/rows format, callbacks and pitfalls.