Skip to content

Kirby 6.0.0

Range

A handy slider

Field options

Name Type Default Description
after arrayorstring null Optional text that will be shown after the input
autofocus bool false Sets the focus on this field when the form loads. Only the first field with this option gets focus
before arrayorstring null Optional text that will be shown before the input
default mixed null Default value for the field, which will be used when a page/file/user is created
disabled bool false If true, the field is no longer editable
help arrayorstring null Optional help text below the field
icon string null Optional icon that will be shown at the end of the field
label arrayorstring no default value The field label can be set as string or associative array with translations
max float 100.0 The highest allowed number
min float null The lowest allowed number
placeholder arrayorstring null Optional placeholder value that will be shown when the field is empty
required bool false If true, the field has to be filled in correctly to be saved.
step stringorfloat null Allowed incremental steps between numbers (i.e 0.5) Use any to allow any decimal value.
tooltip arrayorbool true Enables/disables the tooltip and sets the before and after values
translate bool true Should the field be translatable?
validate arrayorstring null Additional validator rules for the value, e.g. email or ['minLength' => 3]
when array null Conditions when the field will be shown
width string '1/1' The width of the field in the field grid. Available widths: 1/1, 1/2, 1/3, 1/4, 2/3, 3/4

The range field creates a flexible slider, that can be used to display numbered values in a more visual and intuitive way.

Example

fields:
  budget:
    label: Budget
    type: range
    step: 100
    min: 0
    max: 10000
    tooltip:
      before: $

before & after values

The range field can show additional text before or after the input. This is great when you need a price field for example:

fields:
  price:
    label: Price
    type: range
    min: 0
    after: €

How to use in templates/snippets

Echo the field value:

<?= $page->range() ?>

Convert the field value to an integer:

<?= $page->range()->toInt() ?>

Convert the field value to a float:

<?= $page->range()->toFloat() ?>

For more field manipulations, check out Kirby's field methods.

Update programmatically

To change the field value from PHP, pass a number to $page->update():

$page->update([
  'budget' => 500
]);