Range Field
The range field provides a slider input for selecting numeric values within a range. It's perfect for volume controls, rating sliders, and any scenario where users need to select a value from a continuous range.
Namespace
JobMetric\CustomField\CustomFields\Range\Range
Overview
The range field renders as an HTML <input type="range"> element. It provides a visual slider interface for selecting numeric values within a specified range. The package automatically adds the form-range class for Bootstrap styling.
When to Use
Use the range field when you need:
- Slider controls - Volume, brightness, opacity
- Range selection - Price ranges, age ranges, quantity ranges
- Rating sliders - Star ratings, satisfaction ratings
- Continuous values - Any numeric value within a range
- Visual input - When a slider is more intuitive than a number input
Example scenarios:
- Volume control
- Price range filter
- Age range selection
- Rating slider (1-5 stars)
- Brightness/opacity control
Builder Method
CustomFieldBuilder::range()
Available Methods
Range-Specific Attributes
min(?int $min)- Set minimum valuemax(?int $max)- Set maximum valuestep(?int $step)- Set step increment
Common Attributes
name(string $name, ?string $uniq = null)- Set field nameid(?string $id)- Set field IDclass(?string $class)- Set CSS classvalue(mixed $value)- Set field value (default: midpoint of min/max)
Common Properties
required()- Make field requireddisabled()- Disable the fieldreadonly()- Make field readonlyautofocus()- Auto-focus on page load
Field Labels
label(?string $label)- Set field labelinfo(?string $info)- Set help/info text
Validation
validation(array|string $rules)- Set validation rules
Basic Example
use JobMetric\CustomField\Facades\CustomFieldBuilder;
$range = CustomFieldBuilder::range()
->name('volume')
->label('Volume')
->min(0)
->max(100)
->build();
$result = $range->toHtml();
echo $result['body'];
Advanced Examples
Volume Control
$range = CustomFieldBuilder::range()
->name('volume')
->label('Volume')
->min(0)
->max(100)
->step(1)
->value(50)
->info('Adjust volume from 0 to 100')
->build();
Rating Slider
$range = CustomFieldBuilder::range()
->name('rating')
->label('Rating')
->min(1)
->max(5)
->step(1)
->value(3)
->required()
->info('Rate from 1 to 5')
->build();
Price Range Filter
$range = CustomFieldBuilder::range()
->name('price_range')
->label('Price Range')
->min(0)
->max(1000)
->step(10)
->value(500)
->info('Select maximum price')
->build();
With Validation
$range = CustomFieldBuilder::range()
->name('quantity')
->label('Quantity')
->min(1)
->max(100)
->step(1)
->required()
->validation(['required', 'integer', 'min:1', 'max:100'])
->build();
Brightness Control
$range = CustomFieldBuilder::range()
->name('brightness')
->label('Brightness')
->min(0)
->max(100)
->step(1)
->value(75)
->info('Adjust brightness (0-100)')
->build();
Rendering
HTML Output
$result = $range->toHtml();
// $result contains:
// [
// 'body' => '<input type="range" ...>',
// 'scripts' => [],
// 'styles' => []
// ]
echo $result['body'];
Array Output
$array = $range->toArray();
// Returns complete field configuration
HTML Output
The range field renders as:
<input
type="range"
name="volume"
id="volume"
class="form-range"
min="0"
max="100"
step="1"
value="50"
/>
Displaying Current Value
To display the current value of a range slider, you can use JavaScript:
<input type="range" name="volume" id="volume" min="0" max="100" />
<span id="volume-value">50</span>
<script>
document.getElementById('volume').addEventListener('input', function(e) {
document.getElementById('volume-value').textContent = e.target.value;
});
</script>
Related Documentation
- Field Attributes - All available attributes
- Field Properties - Field properties
- CustomFieldBuilder - Builder API reference