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.

Dark Input Dialog

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

  1. Use appropriate input types - Match input type to expected data

  2. Provide clear placeholders - Help users understand expected format

  3. Implement validation - Validate input on both client and server

  4. Use callbacks effectively - Prefer callbacks over events for better context

  5. Set reasonable limits - Use appropriate min/max length constraints

  6. Handle cancellation gracefully - Always handle the case where users cancel

  7. Test edge cases - Test with empty input, special characters, etc.

  8. Provide user feedback - Use notifications to confirm actions

  9. Server-side validation - Always validate input on the server side as well

Troubleshooting

Input Dialog Not Showing

  1. Check that B2Lib is properly initialized

  2. Verify no other modal dialogs are active

  3. Check console for error messages from B2Lib.Debug

  4. Ensure NUI focus is available

  5. Verify B2Lib.UI is available (check with print(B2Lib.UI ~= nil))

Validation Not Working

  1. Verify validation function returns boolean

  2. Check for JavaScript errors in console

  3. Test validation function independently

  4. Ensure validation logic is correct

  5. Check that validation function doesn't throw errors

Input Not Submitting

  1. Check that required fields are filled

  2. Verify validation passes

  3. Ensure callback functions are properly defined

  4. Check for conflicting key bindings

  5. Verify server-side callback handling

Server-Side Issues

  1. Ensure player ID is valid when calling from server

  2. Check that callback functions don't reference invalid variables

  3. Verify network events are properly registered

  4. Check server console for callback-related errors

NUI Focus Issues

  1. Verify no other resources are interfering with NUI focus

  2. Check that input dialogs are properly closed before opening new ones

  3. Ensure proper cleanup in callback functions

  4. Test with minimal resource load to isolate conflicts


Last updated