mitydigital/statamic-variable-number-fieldtype
A Statamic fieldtype addon that adds a flexible Variable Number field to your control panel, making it easy to capture and display numeric values in your content. Simple to install and configure, it drops straight into your existing fieldsets and blueprints.
This is a single-purpose Statamic addon: it registers a variable_number fieldtype so a content editor can enter a number whose digit count (or segment layout) isn't fixed — order references, serials, SKUs, invoice numbers — instead of forcing a padded or fixed-width integer.
composer require mitydigital/statamic-variable-number-fieldtype:^3.0^2.1 (composer require mitydigital/statamic-variable-number-fieldtype:^2.1)php artisan statamic:stache:clear.src/ — the fieldtype class and its Vue component are small enough to read end-to-end in ten minutes. That is genuinely the fastest way to learn the exact options, because the addon's surface area is one field.# resources/blueprints/collections/orders/order.yaml
title: Order Number
fields:
-
handle: order_number
field:
type: variable_number
display: 'Order Number'
# addon-specific options (segment/digit config) per the README
instructions: 'Enter the reference exactly as issued.'
Blueprint-first, then content. Configure the field in the blueprint and create one entry before wiring up any templates. The fieldtype's behaviour on save is easier to observe than to infer from docs, and it tells you immediately whether values are persisted as strings (usually yes) or coerced to integers.
Store and render as a string. Treat the value as an opaque reference in Antlers/Blade rather than a number:
{{ if order_number }}
<span class="font-mono">{{ order_number }}</span>
{{ /if }}
Avoid arithmetic, {{ order_number | multiply }}, or numeric casts anywhere downstream. A reference number that happens to contain leading zeros or separators is text, and it should never round-trip through an int.
Use it where editors were previously fighting a text field. The highest-value migration is replacing free-text text fields that hold reference numbers. Editors get input constraints; you get cleaner data. Do this per-blueprint, one field at a time, with a content backup — see Gotchas.
Pairs well with conditional/revealer fields. A variable number commonly belongs in a "generate or enter manually" flow: a toggle field plus this field, with if/unless visibility on the blueprint so the manual input only appears when auto-generation is off.
Programmatic access. If you generate values in a controller, command, or import, set the field through the entry API and let Statamic's fieldtype handle normalisation rather than mutating the raw YAML:
$entry->set('order_number', $reference);
$entry->save();
Testing. Assert against the stored value after save rather than against the Vue component; the fieldtype is a UI layer over content storage, so a Pest/PHPUnit test that saves an entry and re-reads $entry->get('order_number') covers the part that can actually break in production.
Sorting and querying. If you need "highest reference number", don't lean on collection sort: order_number — string sorting on variable-length values is where you get 1000 before 999. Where ordering matters, pair this field with a separate integer field (or a timestamp) as the sort key and keep the variable number purely as a human-facing label.
^3.0 will not install, and there is no reason to chase it. Conversely, if you're upgrading to Statamic 6, budget for this major bump plus whatever else your Statamic 6 upgrade requires (Laravel and PHP floors move with it) — pin the addon alongside statamic/cms in the same PR so the constraint matrix resolves in one go.content/ (or your database) before changing a live blueprint, and prefer adding a new field over mutating one that already holds production references.int — a resource, an API transformer, a Blade (int) cast — 000123 becomes 123 and the reference no longer matches your ERP. Keep it a string end to end.sort: order_number will surprise you. Use a numeric companion field for ordering.php artisan statamic:stache:clear. A missing fieldtype in the picker or a stale blueprint is almost always cache, not a broken install.rules/validate before adding your own blueprint validate: entry, so you don't double up or conflict.validate rules for anything business-critical (uniqueness of an order number, for example) — the fieldtype constrains input format, not your application's invariants.^3.0 constraint is fine, but avoid dev-main on anything content-facing. Read the changelog on each bump — future majors will likely follow Statamic majors again, so the version number tracks the CMS, not the feature set.statamic/cms, bump this addon to ^3.0, clear Stache, then re-save one entry of each blueprint that uses the field and diff the content file. If the diff is empty, you're done.How can I help you explore Laravel packages today?