2025-03-18 18:46:09 +11:00
|
|
|
--[[
|
|
|
|
|
https://github.com/overextended/ox_lib
|
|
|
|
|
|
|
|
|
|
This file is licensed under LGPL-3.0 or higher <https://www.gnu.org/licenses/lgpl-3.0.en.html>
|
|
|
|
|
|
2025-03-29 21:44:03 +11:00
|
|
|
Copyright © 2025 Linden <https://github.com/thelindat>
|
2025-03-18 18:46:09 +11:00
|
|
|
]]
|
|
|
|
|
|
2022-04-18 23:30:58 +10:00
|
|
|
local input
|
|
|
|
|
|
2022-09-18 09:06:32 +10:00
|
|
|
---@class InputDialogRowProps
|
2023-09-01 20:13:16 +02:00
|
|
|
---@field type 'input' | 'number' | 'checkbox' | 'select' | 'slider' | 'multi-select' | 'date' | 'date-range' | 'time' | 'textarea' | 'color'
|
2022-09-18 09:06:32 +10:00
|
|
|
---@field label string
|
|
|
|
|
---@field options? { value: string, label: string, default?: string }[]
|
|
|
|
|
---@field password? boolean
|
2023-03-10 19:38:34 +00:00
|
|
|
---@field icon? string | {[1]: IconProp, [2]: string};
|
2022-09-18 09:06:32 +10:00
|
|
|
---@field iconColor? string
|
|
|
|
|
---@field placeholder? string
|
|
|
|
|
---@field default? string | number
|
2022-10-27 03:17:53 -04:00
|
|
|
---@field disabled? boolean
|
2022-09-18 09:06:32 +10:00
|
|
|
---@field checked? boolean
|
|
|
|
|
---@field min? number
|
|
|
|
|
---@field max? number
|
|
|
|
|
---@field step? number
|
2023-02-17 11:28:53 +01:00
|
|
|
---@field autosize? boolean
|
|
|
|
|
---@field required? boolean
|
|
|
|
|
---@field format? string
|
2023-09-11 21:17:35 +00:00
|
|
|
---@field returnString? boolean
|
2024-02-17 12:10:05 +01:00
|
|
|
---@field clearable? boolean
|
2024-03-10 06:06:11 -07:00
|
|
|
---@field searchable? boolean
|
2022-10-27 13:45:27 +02:00
|
|
|
---@field description? string
|
2024-05-07 20:28:52 +02:00
|
|
|
---@field maxSelectedValues? number
|
2025-07-23 17:10:57 +02:00
|
|
|
---@field minLength? number
|
|
|
|
|
---@field maxLength? number
|
2022-04-11 15:26:10 +02:00
|
|
|
|
2023-01-11 20:54:29 +01:00
|
|
|
---@class InputDialogOptionsProps
|
|
|
|
|
---@field allowCancel? boolean
|
|
|
|
|
|
2022-09-18 09:06:32 +10:00
|
|
|
---@param heading string
|
|
|
|
|
---@param rows string[] | InputDialogRowProps[]
|
2023-02-25 18:20:14 +11:00
|
|
|
---@param options InputDialogOptionsProps[]?
|
2022-09-18 09:06:32 +10:00
|
|
|
---@return string[] | number[] | boolean[] | nil
|
2023-01-11 20:54:29 +01:00
|
|
|
function lib.inputDialog(heading, rows, options)
|
2022-09-18 09:06:32 +10:00
|
|
|
if input then return end
|
|
|
|
|
input = promise.new()
|
2022-05-02 13:51:01 +02:00
|
|
|
|
2022-09-18 09:06:32 +10:00
|
|
|
-- Backwards compat with string tables
|
|
|
|
|
for i = 1, #rows do
|
|
|
|
|
if type(rows[i]) == 'string' then
|
|
|
|
|
rows[i] = { type = 'input', label = rows[i] --[[@as string]] }
|
|
|
|
|
end
|
|
|
|
|
end
|
2022-05-02 13:51:01 +02:00
|
|
|
|
2023-03-23 05:55:16 +11:00
|
|
|
lib.setNuiFocus(false)
|
2022-09-18 09:06:32 +10:00
|
|
|
SendNUIMessage({
|
|
|
|
|
action = 'openDialog',
|
|
|
|
|
data = {
|
|
|
|
|
heading = heading,
|
2023-01-11 20:54:29 +01:00
|
|
|
rows = rows,
|
|
|
|
|
options = options
|
2022-09-18 09:06:32 +10:00
|
|
|
}
|
|
|
|
|
})
|
2022-04-18 23:30:58 +10:00
|
|
|
|
2022-09-18 09:06:32 +10:00
|
|
|
return Citizen.Await(input)
|
2022-04-11 15:26:10 +02:00
|
|
|
end
|
|
|
|
|
|
2022-09-29 11:39:30 +02:00
|
|
|
function lib.closeInputDialog()
|
|
|
|
|
if not input then return end
|
2023-03-23 05:55:16 +11:00
|
|
|
|
|
|
|
|
lib.resetNuiFocus()
|
2022-09-29 11:39:30 +02:00
|
|
|
SendNUIMessage({
|
|
|
|
|
action = 'closeInputDialog'
|
|
|
|
|
})
|
2023-03-23 05:55:16 +11:00
|
|
|
|
|
|
|
|
input:resolve(nil)
|
|
|
|
|
input = nil
|
2022-09-29 11:39:30 +02:00
|
|
|
end
|
|
|
|
|
|
2022-04-11 15:26:10 +02:00
|
|
|
RegisterNUICallback('inputData', function(data, cb)
|
2022-09-18 09:06:32 +10:00
|
|
|
cb(1)
|
2023-03-23 05:55:16 +11:00
|
|
|
lib.resetNuiFocus()
|
|
|
|
|
|
2022-09-18 09:06:32 +10:00
|
|
|
local promise = input
|
|
|
|
|
input = nil
|
2023-03-23 05:55:16 +11:00
|
|
|
|
2022-09-18 09:06:32 +10:00
|
|
|
promise:resolve(data)
|
2022-10-27 13:45:27 +02:00
|
|
|
end)
|