Range
Range extension for nette forms, (*1)
Demo
- Composer package: https://packagist.org/packages/landrisek/nette-range
Installation
- Install composer if you don't have it yet
- run
composer require landrisek/nette-range:1.*
- Copy files from nette-range/assets to your www/assets and include them into your template or follow Optional settings
Required settings
Edit your config.neon, (*2)
extensions:
range: Range\RangeExtension, (*3)
Add to template:, (*4)
<a href="#" onclick="submitRange();">{input yourSubmitButton}</a>
Add in MyForm::attached:
$this->addRange('myRangeId', 'My range label')
->setDefaultValue('min'=>$minimalValue,'max'=>$maximalValue,'from'=>$fromValue,'to'=>$toValue);, (*5)
Add in MyForm::render:
$this->templates->ranges = ['myRangeId','myOtherRangeId'];, (*6)
In formSucced method you will get array:, (*7)
public function formSucceed($form) {
$values = $form->getValues();
$from = $values['myRangeId']['from'];
$to = $values['myRangeId']['to'];
}
Optional settings
Edit your config.neon:, (*8)
services:
- Range\IRangeFactory, (*9)
Add to your form / component:, (*10)
/** @var IRangeFactory */
private $rangeFactory;
public function __construct(Range\IRangeFactory $rangeFactory) {
$this->rangeFactory = $rangeFactory;
}
protected function createComponentRange() {
return $this->rangeFactory->create();
}
Add to template of your form / component:, (*11)
{control range:head}
{control $myForm}
{control range:footer}