Mity Docs Mity Docs for Mity Digital
Variable Number Fieldtype Documentation

Why do I need this?

Statamic's Blueprints offer a huge amount of flexibility when building Forms for your site, with a range of fieldtypes to select from.

However, we have had a repeating need from clients to allow their users to select from a range of numbers, and while this can be achieved with custom coding in a specific project, would require repeating code across multiple projects.

Why don't I just use a select box, and conditional fields?

You could - but you would also need to write your own JavaScript logic to show/hide the fields.

The bigger issue is that you'll probably need to write your own markup for those specific fields - which makes looping through and using Statamic's fields helpers a little more complicated in your Antlers files.

What is the biggest advantage of this?

When you add a Text field to your Blueprint, Statamic stores the value provided against that field's handle.

With a Select field, the same thing. One handle, one value.

If you use multiple fields to achieve the variable number behaviour, you now have multiple fields stored with your Form Submission. Let's say you have a Select field for your numbers, with an option that will conditionally show a "custom" field. If you need to do something with the value selected, you now need to check both the Select field (for its value, or if the "custom" option was selected), and if so, also the Custom field.

This addon stores the end result from the user as a single field, combining the behaviour of those two fields above, but storing only a single value.

This makes it easier to work with:

  • in submission emails,

  • when listening for a submission, or

  • handling redirects