Have you seen our new video tutorials? Check it out!

Slider Field Type

The slider field type provides a fancy range slider input.

Introduction

anomaly.field_type.slider

The slider field type provides a range slider input that allows users to select a value between a range of values.

Configuration

Below is the full configuration available with defaults values:

"example" => [
    "type"   => "anomaly.field_type.slider",
    "config" => [
        "min"           => 0,
        "max"           => 10,
        "step"          => 1,
        "range"         => null,
        "unit"          => null,
        "default_value" => null,
    ],
],
Configuration
Key Example Description

min

-100

The minumum value selectable.

max

100

The maximum value selectable.

step

5

The interval between selectable values.

range

true

The range mode. Valid options are false, true, min, and max.

unit

Units

The unit label.

default_value

50,75

The default value.

Usage

This section will show you how to use the field type via API and in the view layer.

Setting Values

You can set the value by using a single value with the slider limits:

$entry->example = 10;

For range enabled sliders you can set the value with a comma separated value:

$entry->example = 10,20

Basic Output

This field type returns the value as stored in the database by default.

For non-ranges this will be a single value. For range enabled sliders the values are separated with a comma.

$entry->example; // 10,20 or 10

Presenter Output

This section will show you how to use the decorated value provided by the \Anomaly\SliderFieldType\SliderFieldTypePresenter class.

SliderFieldTypePresenter::top()

The top method returns the top end value for range enabled sliders.

Returns: integer
Example
$decorated->example->top(); // 20
Twig
{{ decorated.example.top() }} // 20

SliderFieldTypePresenter::bottom()

The bottom method returns the bottom end value for range enabled sliders.

Returns: integer
Example
$decorated->example->bottom(); // 10
Twig
{{ decorated.example.bottom() }} // 10

SliderFieldTypePresenter::values()

The values method returns the bottom and top end values in an array for range enabled sliders.

Returns: array
Example
$decorated->example->values()[0];
Twig
{{ decorated.example.values()|first }}