Skip to content

Input Module โ€‹

The Input module provides two methods for gathering user input in RedM:

  1. NUI (HTML-based) input forms
  2. Native game input dialog

Getting Started โ€‹

lua
local Input = exports.bln_lib:input()

NUI Input โ€‹

Simple Input โ€‹

Quick way to create a single input field dialog.

lua
Input.simpleOpen(
    function(result)               -- Callback
        print("Input result: " .. result)
    end,
    "Enter Name",                 -- Title
    "Character Name",             -- Input Label
    "Enter your character name",  -- Placeholder
    "Submit",                     -- OK Button Label
    "Cancel"                      -- Cancel Button Label
)

Custom Form Input โ€‹

Create custom forms with multiple inputs.

lua
Input.open({
    isRTL = false,               -- Right-to-left support
    title = "Character Creation",
    labels = {
        submitLabel = "Create",
        closeLabel = "Cancel"
    },
    inputs = {
        {
            name = "firstname",
            label = "First Name",
            type = "text",
            value = "",
            attributes = {
                placeholder = "Enter first name"
            }
        },
        {
            name = "age",
            label = "Age",
            type = "number",
            value = "18",
            attributes = {
                min = "18",
                max = "90"
            }
        }
    }
}, function(data)
    print("First Name: " .. data.firstname)
    print("Age: " .. data.age)
end)

Close NUI Input โ€‹

Manually close the NUI input form.

lua
Input.close()

Native Input โ€‹

Use the game's built-in keyboard input.

lua
local result = Input.native(
    "Enter Name",           -- Label
    "John Doe",            -- Placeholder
    20                     -- Max Length (optional)
)
print("Input result: " .. result)

Examples โ€‹

Character Creation โ€‹

lua
-- Using NUI input for multiple fields
Input.open({
    title = "Create Character",
    labels = {
        submitLabel = "Create",
        closeLabel = "Cancel"
    },
    inputs = {
        {
            name = "firstname",
            label = "First Name",
            type = "text",
            value = "",
            attributes = {
                placeholder = "Enter first name"
            }
        },
        {
            name = "lastname",
            label = "Last Name",
            type = "text",
            value = "",
            attributes = {
                placeholder = "Enter last name"
            }
        },
        {
            name = "age",
            label = "Age",
            type = "number",
            value = "18"
        }
    }
}, function(data)
    -- Process the form data
    CreateCharacter(data.firstname, data.lastname, data.age)
end)

Quick Name Input โ€‹

lua
-- Using simple NUI input
Input.simpleOpen(
    function(name)
        if name then
            SetCharacterName(name)
        end
    end,
    "Name Your Horse",
    "Horse Name",
    "Enter horse name",
    "Name",
    "Cancel"
)

Password Entry โ€‹

lua
-- Using native input for sensitive data
local password = Input.native(
    "Enter Password",
    "****",
    8
)
CheckPassword(password)

Input Types for NUI Forms โ€‹

The NUI form supports various input types:

lua
{
    -- Text input
    {
        type = "text",
        name = "username"
    },
    
    -- Number input
    {
        type = "number",
        name = "age"
    },
    
    -- Password input
    {
        type = "password",
        name = "password"
    }
}

Best Practices โ€‹

  1. Choose the right input method:

    • Use NUI for complex forms
    • Use native input for simple text entry
  2. Always provide clear labels and placeholders

  3. Handle empty responses:

lua
Input.simpleOpen(function(result)
    if result then
        -- Process valid input
    else
        -- Handle empty/cancelled input
    end
end, ...)
  1. Set appropriate max lengths for native input:
lua
-- For names
local name = Input.native("Enter Name", "", 30)

-- For short codes
local code = Input.native("Enter Code", "", 6)