Input Dialog
The Input dialog system provides modal input forms for collecting user data with validation, formatting, and customization options. Perfect for gathering text input, numbers, and other user data.

Input Dialogs
Modal input dialogs for collecting user data with validation and customization options. Perfect for gathering text input, numbers, and other user data with comprehensive validation support.
Features
Multiple Input Types: Text, number, password, email, and more
Validation Support: Built-in and custom validation rules
Theme Integration: Adapts to dark/light themes automatically
Modal Design: Focused input experience with backdrop
Keyboard Navigation: Full keyboard support with Enter/Escape handling
NUI Focus Management: Automatic cursor and keyboard focus handling
Server-Side Support: Can be triggered from server-side with callbacks
B2Lib.UI.input
Display an input dialog to collect user data.
playerId: number (server-side only) Player server ID to show the input dialog to.
options: table (object)
title?: string Dialog title (default: 'Input Required').
subtitle?: string Dialog subtitle (default: empty string).
placeholder?: string Input placeholder text (default: 'Enter value...').
defaultValue?: string Pre-filled input value (default: empty string).
type?: string Input type -
'text','number','password'(default:'text').required?: boolean Whether input is required (default: true).
maxLength?: number Maximum character limit (default: 255).
minLength?: number Minimum character requirement (default: 0).
validation?: function Custom validation function.
confirmText?: string Confirm button text (default: 'Confirm').
cancelText?: string Cancel button text (default: 'Cancel').
allowCancel?: boolean Whether cancel is allowed (default: true).
position?: string Dialog position (default: from config).
showBackground?: boolean Show background overlay (default: from config).
id?: string Custom input dialog ID (default: auto-generated).
callback: function|nil (optional) Callback function to handle the input result.
Returns: number|boolean - Input dialog ID on success, false on failure
Example:
B2Lib.UI.hideInput
Hide the currently active input dialog.
Returns: boolean - Success status
Example:
Input Types
Text Input
Standard text input for general text data.
Number Input
Numeric input with automatic validation.
Password Input
Masked input for sensitive data.
Validation
Input dialogs support custom validation functions:
Custom Validation
Events
The Input system triggers events for handling user input:
b2lib:input-submitted
Triggered when user submits input (client-side only).
Note: When using callbacks with B2Lib.UI.input(), the callback function is preferred over event handlers as it provides better context and error handling.
Server-Side Usage
Input with Callback
Multi-Step Input Process
Configuration
Configure Input dialog defaults in Config.lua:
Advanced Examples
Conditional Input Based on User Type
Input with Complex Validation
Dynamic Input Based on Context
Best Practices
Use appropriate input types - Match input type to expected data
Provide clear placeholders - Help users understand expected format
Implement validation - Validate input on both client and server
Use callbacks effectively - Prefer callbacks over events for better context
Set reasonable limits - Use appropriate min/max length constraints
Handle cancellation gracefully - Always handle the case where users cancel
Test edge cases - Test with empty input, special characters, etc.
Provide user feedback - Use notifications to confirm actions
Server-side validation - Always validate input on the server side as well
Troubleshooting
Input Dialog Not Showing
Check that B2Lib is properly initialized
Verify no other modal dialogs are active
Check console for error messages from B2Lib.Debug
Ensure NUI focus is available
Verify B2Lib.UI is available (check with
print(B2Lib.UI ~= nil))
Validation Not Working
Verify validation function returns boolean
Check for JavaScript errors in console
Test validation function independently
Ensure validation logic is correct
Check that validation function doesn't throw errors
Input Not Submitting
Check that required fields are filled
Verify validation passes
Ensure callback functions are properly defined
Check for conflicting key bindings
Verify server-side callback handling
Server-Side Issues
Ensure player ID is valid when calling from server
Check that callback functions don't reference invalid variables
Verify network events are properly registered
Check server console for callback-related errors
NUI Focus Issues
Verify no other resources are interfering with NUI focus
Check that input dialogs are properly closed before opening new ones
Ensure proper cleanup in callback functions
Test with minimal resource load to isolate conflicts
Last updated