A spinner field for SilverStripe using jQuery UI's Spinner Widget.
A spinner field for SilverStripe using jQuery UI's Spinner Widget providing a nice interface for number input fields and the ability to customize them.
"require": {
"php": "^5.4",
"silverstripe/framework": "~3.1"
}
composer require jjjjjjjjjjjjjjjjjjjj/silverstripe-spinner-field
SpinnerField::create(
// Field name
'Answer',
// Label
'What is the answer to the ultimate question of life, the universe, and everything?',
// Initial value
rand(0, 42),
// Optional options (see available options below under heading: UI settings)
[
'min' => 0,
'max' => 42,
'step' => 3 // Increment and decrement in steps of 3
]
);
You can configure the spinner widget's UI by passing an array of options in the constructor like shown above, or you could do something like:
// Setting a batch of options.
$spinnerField->setUIOptions(
[
'disabled' => true,
'max' => 314159265359,
'page' => 100000000000,
'icon_up' => 'ui-icon-plus',
'icon_down' => 'ui-icon-minus'
]
);
// On second thought...
$spinnerField->setUIOption('disabled', false);
Here's a list of available UI options. See https://api.jqueryui.com/spinner/ for detailed description of the options and what they do.
// Available options and their default values
[
culture => null,
disabled => false,
icon_down => 'ui-icon-triangle-1-s',
icon_up => 'ui-icon-triangle-1-n',
incremental => true,
max => null,
min => null,
numberFormat => null, // Currently only 'n'||null is supported
page => 10,
step => 1
]
/**
* Enforce step validation. Will cause validation to fail if input is
* not evenly divisible with the 'step' UI option. Example: if 'step'
* is set to 4, validation will fail for 0 !== $input % 4
*
* @var bool
*/
protected $enforceStepValidation = false;
/**
* Will cause validation to fail if input is below the 'min' UI option.
*
* @var bool
*/
protected $enforceBelowMinValidation = true;
/**
* Will cause validation to fail if input is above the 'max' UI option.
*
* @var bool
*/
protected $enforceAboveMaxValidation = true;
Furthermore see NumericField for inherited field settings.
Module rating system helping users find modules that are well supported. For more on how the rating system works visit Module standards
Score not correct? Let us know there is a problem