Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.

feat(input): added lib.getOpenInputDialog #738

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions resource/interface/client/input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
Copyright (c) 2025 Linden <https://github.com/thelindat/fivem>
]]

local input
local input, inputData

---@class InputDialogRowProps
---@field type 'input' | 'number' | 'checkbox' | 'select' | 'slider' | 'multi-select' | 'date' | 'date-range' | 'time' | 'textarea' | 'color'
---@field label string
---@field options? { value: string, label: string, default?: string }[]
---@field password? boolean
---@field icon? string | {[1]: IconProp, [2]: string};
---@field icon? string | {[1]: IconProp, [2]: string}
---@field iconColor? string
---@field placeholder? string
---@field default? string | number
Expand Down Expand Up @@ -41,6 +41,7 @@ local input
function lib.inputDialog(heading, rows, options)
if input then return end
input = promise.new()
inputData = { heading = heading, rows = rows, options = options }

-- Backwards compat with string tables
for i = 1, #rows do
Expand All @@ -50,16 +51,13 @@ function lib.inputDialog(heading, rows, options)
end

lib.setNuiFocus(false)
SendNUIMessage({
action = 'openDialog',
data = {
heading = heading,
rows = rows,
options = options
}
})
SendNUIMessage({ action = 'openDialog', data = inputData })

return input:await()
end

return Citizen.Await(input)
function lib.getOpenInputDialog()
return input ~= nil, inputData
end

function lib.closeInputDialog()
Expand All @@ -69,17 +67,16 @@ function lib.closeInputDialog()
SendNUIMessage({
action = 'closeInputDialog'
})

input:resolve(nil)
input = nil
input, inputData = nil, nil
end

RegisterNUICallback('inputData', function(data, cb)
cb(1)
lib.resetNuiFocus()

local promise = input
input = nil

input, inputData = nil, nil
promise:resolve(data)
end)