Files
community_bridge/modules/input/_qb-input.lua
T

92 lines
3.1 KiB
Lua
Raw Normal View History

2025-04-10 22:21:38 -04:00
local resourceName = "qb-input"
local configValue = BridgeClientConfig.InputSystem
if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (configValue ~= "auto" and configValue ~= resourceName) then return end
2025-01-18 05:31:33 -06:00
function OxTypeToQBType(_type)
if _type == "input" then
return "text"
elseif _type == "number" then
return "number"
elseif _type == "checkbox" then
return "checkbox"
elseif _type == "select" then
return "select"
elseif _type == "multi-select" then
return "select"
elseif _type == "slider" then
return "number"
elseif _type == "color" then
return "text"
elseif _type == "date" then
return "date"
elseif _type == "date-range" then
return "date"
elseif _type == "time" then
return "time"
elseif _type == "textarea" then
return "text"
end
end
function OxToQBInput(data)
local returnData = {}
for i, v in pairs(data) do
local input = {
text = v.label,
name = i,
type = OxTypeToQBType(v.type),
isRequired = v.required,
2025-04-20 10:40:14 +01:00
default = v.default or "",
2025-01-18 05:31:33 -06:00
}
if v.type == "select" then
input.text = ""
2025-04-10 17:07:13 -05:00
input.options = {}
for k, j in pairs(v.options) do
table.insert(input.options, {value = j.value, text = j.label})
end
2025-01-18 05:31:33 -06:00
elseif v.type == "checkbox" then
input.text = ""
2025-04-10 17:07:13 -05:00
input.options = {}
2025-04-20 11:20:34 +01:00
if v.options then -- Checks if options varible is valid so checkboxes are bundled together (not used by ox for each checkpoint)
for k, j in pairs(v.options) do
table.insert(input.options, {value = j.value, text = j.label, checked = j.checked}) -- added checked option (used to show box as ticked or not)
end
else -- If options is not valid or people pass a single checkbox then it will be a single checkbox per entry
table.insert(input.options, {value = v.value, text = v.label, checked = v.checked}) -- Kept value just incase it's used for other stuffs
2025-04-10 17:07:13 -05:00
end
2025-01-18 05:31:33 -06:00
end
table.insert(returnData, input)
end
return returnData
end
function OpenInput(title, data, isQBFormat, submitText)
local input = data.inputs
if not isQBFormat then
input = OxToQBInput(data)
end
2025-02-16 06:52:33 -05:00
local returnData = exports['qb-input']:ShowInput({
2025-01-18 05:31:33 -06:00
header = title,
submitText = submitText or "Submit",
inputs = input
2025-02-05 22:51:59 -05:00
})
2025-02-16 06:52:33 -05:00
if not returnData then return end
if returnData[1] then return returnData end
--converting to standard format (ox)
local convertedData = {}
2025-04-10 22:21:38 -04:00
if isQBFormat then
2025-02-16 06:52:33 -05:00
for i, v in pairs(input) do
for k, j in pairs(returnData) do
if k == v.text then
convertedData[tonumber(i)] = j
end
end
end
return convertedData
end
for i, v in pairs(returnData) do
convertedData[tonumber(i)] = v
end
return convertedData
2025-04-20 10:40:14 +01:00
end