Skip to main content
The Number component renders a number input field with HTML5 numeric validation, Bootstrap styling, and validation error handling.

Basic Usage

<x-forms::number name="quantity" label="Quantity" />

Attributes

name
string
required
The input name attribute. Used for form submission and error handling.
label
string
default:""
The label text displayed for the input. If empty, a label will be auto-generated from the name.
model
mixed
default:"null"
The model instance to bind to. The component will automatically fetch the value from the model using the name attribute.
default
mixed
default:"null"
The default value if no model value or old input exists.
showErrors
boolean
default:"true"
Whether to display validation errors below the input.
showLabel
boolean
default:"true"
Whether to display the label. Set to false to hide the label.
placeholder
string
default:""
Custom placeholder text for the input.
showPlaceholder
boolean
default:"false"
Automatically use the label as placeholder text when true.
required
boolean
default:"false"
Mark the input as required. Adds HTML5 required attribute and displays a required indicator on the label.
inline
boolean
default:"false"
Display the label and input inline (horizontal layout).
floating
boolean
default:"false"
Enable Bootstrap floating label style.
inlineLabelClass
string
default:""
Additional CSS classes for the inline label wrapper.
inlineInputClass
string
default:""
Additional CSS classes for the inline input wrapper.
showJsErrors
boolean
default:"false"
Enable JavaScript-based error display for client-side validation.
framework
string
default:""
Specify a custom framework theme. Defaults to the configured framework.

Examples

Basic Number Input

<x-forms::number 
    name="quantity" 
    label="Quantity" 
/>

With Min and Max Values

<x-forms::number 
    name="age" 
    label="Age"
    min="0"
    max="120"
/>

With Step Increment

<x-forms::number 
    name="price" 
    label="Price"
    step="0.01"
    min="0"
/>

Required Field

<x-forms::number 
    name="quantity" 
    label="Quantity"
    :required="true"
    min="1"
/>

With Model Binding

<x-forms::number 
    name="stock" 
    label="Stock Quantity"
    :model="$product"
/>

With Default Value

<x-forms::number 
    name="quantity" 
    label="Quantity"
    :default="1"
/>

With Placeholder

<x-forms::number 
    name="quantity" 
    label="Quantity"
    placeholder="Enter quantity"
/>

Floating Label

<x-forms::number 
    name="amount" 
    label="Amount"
    :floating="true"
/>

Inline Layout

<x-forms::number 
    name="quantity" 
    label="Qty"
    :inline="true"
    inline-label-class="col-md-3"
    inline-input-class="col-md-9"
/>

Without Label

<x-forms::number 
    name="quantity" 
    :show-label="false"
    placeholder="Qty"
/>

Decimal Numbers

<x-forms::number 
    name="price" 
    label="Price ($)"
    step="0.01"
    min="0"
    :required="true"
/>

Percentage Input

<x-forms::number 
    name="discount" 
    label="Discount (%)"
    min="0"
    max="100"
    step="1"
/>

With Help Text

<x-forms::number name="quantity" label="Quantity">
    <x-slot:help>
        Enter the number of items you want to order.
    </x-slot:help>
</x-forms::number>

Product Order Form

<x-forms::form-open>
    <x-forms::select 
        name="product_id" 
        label="Product"
        :options="$products"
        :required="true"
    />
    
    <x-forms::number 
        name="quantity" 
        label="Quantity"
        :required="true"
        min="1"
        max="100"
        :default="1"
    />
    
    <x-forms::number 
        name="price" 
        label="Unit Price"
        step="0.01"
        min="0"
        readonly
    />
    
    <x-forms::submit>Add to Cart</x-forms::submit>
</x-forms::form-open>

Value Resolution

The component resolves the input value in the following order:
  1. Old input (from validation errors)
  2. Model value (if model is provided)
  3. Default value (if specified)
  4. Empty string

HTML5 Number Validation

The number input type provides built-in browser validation:
  • Only accepts numeric input
  • Supports min, max, and step attributes for validation
  • Provides increment/decrement controls
  • Shows browser-specific validation messages
  • Works with HTML5 form validation API

Common Attributes

  • min - Minimum allowed value
  • max - Maximum allowed value
  • step - Increment step (use 0.01 for decimals, 1 for integers)

Validation Error Display

When validation fails, the input automatically:
  • Adds the is-invalid Bootstrap class
  • Displays error messages below the input (if showErrors is true)
  • Preserves user input through Laravel’s old input

Implementation Details

The Number component:
  • Extends the base Input component with type set to number
  • Supports all standard HTML input attributes via attribute merging
  • Leverages browser’s native number validation and controls
  • Integrates with Laravel’s validation error bag
  • Works seamlessly with Laravel’s old input helper
Source: /src/Views/Components/Number.php:12

Build docs developers (and LLMs) love