<x-widget.number>
Number Blade component for Laravel and Livewire
Digits only, with a set number of decimals, prefix, suffix and an action slot. Optional -/+ stepper within min and max, negatives, and thousands grouping. Accepts a decimal comma and still submits 12.50. Works with Livewire wire:model, which always gets the plain number.
php artisan bladewell:add number
- Also adds
- Icon
- Used by
- Filter builder
- Works with
- Laravel 12 and 13, Livewire 3 and 4, Tailwind CSS 4.1+, PHP 8.3+
- Guides
- Build a Laravel form from your validation rules · AI agent actions with Approve and Deny in Laravel · Laravel searchable select that loads from the database
Usage
Livewire
In a Livewire component, bind with wire:model (deferred) or wire:model.live; no name is needed. The property always gets the plain number (1234.5), even with grouped showing 1,234.50 or a decimal comma typed in, and the stepper's -/+ update it too. The field shows the property after every render, so setting it in PHP updates both. Keep it a string or a float: public ?string $amount = null.
<div class="space-y-5">
<x-widget.number label="Amount" grouped suffix="USD" wire:model.live="amount" />
<x-widget.number label="Seats" stepper :decimals="0" min="1" max="20" wire:model.live="seats" />
</div>
On the server
The number can't stop a request that skips it. Here's what to check on your server, and what to keep cheap.
Security
-
min,max,decimalsandnegativeonly act in the browser: a request can send-5,1e9or0.0001. Repeat them in your Form Request withintegerornumeric,between:anddecimal:0,2. -
For money, consider storing integer cents or a
decimalcolumn, neverfloat: floats round, and totals drift by a cent. In Livewire, a string property keeps the exact digits until you save them.
Server cost
-
Without
max:, a huge number can overflow the column: a 500 error, or a value quietly clamped, depending on the database. Matchmax:to the column type.
Examples
Number
Keeps input to digits and the given decimals: 2 by default, 0 for whole numbers, or as many as you need (4 for exchange rates, 8 for crypto). Extra places are cut, not rounded. A decimal comma works too: 12,50 becomes 12.50. prefix and suffix sit inside the box; the action slot sits at the end. negative allows a leading minus. Max fills in the balance from the script beside this.
Show code Hide code
<div class="grid gap-6 sm:grid-cols-2">
<x-widget.number name="amount" label="Amount" placeholder="0.00" suffix="usdt">
<x-slot:action>
<button type="button" class="text-primary text-sm font-medium" data-fill-max="1250.50" aria-controls="amount">Max</button>
</x-slot:action>
</x-widget.number>
<x-widget.number name="price" label="Price" placeholder="0.00" prefix="$" />
<x-widget.number name="adjustment" label="Balance adjustment" prefix="$" value="-25.00" negative />
<x-widget.number name="quantity" label="Quantity" placeholder="0" :decimals="0" />
<x-widget.number name="rate" label="Exchange rate" placeholder="0.0000" :decimals="4" suffix="usd/myr" />
<x-widget.number name="btc" label="Bitcoin" placeholder="0.00000000" :decimals="8" suffix="btc" />
</div>
// Fills the field the button controls. The input event lets the number field re-format it, like typing would.
document.addEventListener('click', (event) => {
const button = event.target.closest('[data-fill-max]');
const field = button && document.getElementById(button.getAttribute('aria-controls'));
if (field) {
field.value = button.dataset.fillMax;
field.dispatchEvent(new Event('input', { bubbles: true }));
}
});
Number stepper
stepper adds - and + buttons (ArrowUp and ArrowDown work too), moving by step within min and max. A typed value outside the range is pulled back in when the field is left.
Show code Hide code
<div class="flex flex-wrap gap-6">
<x-widget.number name="guests" label="Guests" :decimals="0" value="2" :min="1" :max="10" stepper class="max-w-44" />
<x-widget.number name="nights" label="Nights" :decimals="0" value="3" :min="1" :max="30" stepper class="max-w-44" />
</div>
Number grouped
grouped shows thousands separators while typing, the locale's way (1.250.000,50 in de), and still submits 1250000.50.
Show code Hide code
<x-widget.number name="loan" label="Loan amount" prefix="RM" value="1250000" grouped class="max-w-sm" />
Props
Other attributes, such as autocomplete or data-*, are passed through to the element. class styles the component's outer wrapper.
<x-widget.number>
| Prop | Default | Description |
|---|---|---|
| name |
null
|
What it submits as; its error and old input are found under it. Optional with wire:model, which then names it. |
| id |
null
|
Defaults to one made from the name (or the wire:model property). |
| label |
null
|
Shown above the field, and its name for screen readers. |
| value |
null
|
The value to show. Old input wins after a failed submit; with wire:model and no value, the bound Livewire property. |
| placeholder |
null
|
Shown while it's empty. |
| error |
null
|
An error message of your own; otherwise the validation error for the name, from the session or Livewire. |
| info |
null
|
A hint under the field. |
| bag |
'default'
|
Which error bag to read the error from. |
| disabled |
false
|
Greyed out: it can't be changed. |
| readonly |
false
|
Shown, and submitted, but it can't be edited. |
| decimals |
2
|
Decimal places allowed (0 for whole numbers). Comma or dot both type the decimal point. |
| mobile |
false
|
Digits only, for phone-style numbers: no decimals, no minus, and the phone keypad. |
| prefix |
null
|
Text at the start, inside the field (e.g. https://). |
| suffix |
null
|
Text or a small control at the end, inside the field (e.g. a unit). |
| uppercase |
true
|
Shows the suffix in capitals (usdt → USDT). |
| negative |
false
|
Allows a leading minus. |
| min |
null
|
The lowest value: leaving the field pulls it into range, and the stepper stops there. |
| max |
null
|
The highest value, in the same way. |
| step |
null
|
How much the stepper buttons and arrow keys change it (1 by default). |
| stepper |
false
|
− and + buttons, plus ArrowUp and ArrowDown; announced as a spin button. |
| grouped |
false
|
Thousands separators while typing (1,234,567.5); it still submits the plain number. |
| locale |
null
|
The locale for grouping and the decimal point; defaults to the app's. |
Accessibility
All 3 examples above are checked with axe-core against the WCAG 2.2 A and AA rules, in the light theme and the dark one, both as the page draws and with each popover, dialog, toast and tooltip opened, on every change. A change that fails can't be merged. Where axe can't decide, such as contrast on SVG text, the test measures the colours itself instead of letting it pass.
Automated checks can't judge everything: how it sounds in a screen reader, and how it feels to use from the keyboard, still need a person. Check those on your own pages too.
Source
What bladewell:add number writes to your app with the default namespaces. Prefer to copy by hand? Take these files, plus the ones from
the components it also adds and Field, and the theme and base CSS.
resources/views/components/widget/number/index.blade.php Show
resources/js/widget/number/index.js Show
app/View/Widget/ElementIds.php Show
app/View/Widget/FormField.php Show