Multiplier Component ‚item‘ is not attached to 'Nette\Forms\Form
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- jarda256
- Člen | 130
Ahoj, používám webchemistry/forms-multiplier a chtěl bych jím duplikovat iteger políčko a nasext/dependent-select-box. Můj kód vypadá takto v CreateRegistrationFormFactory, ale dostávám pouze Component ‚item‘ is not attached to 'Nette\Forms\Form. Nějak si nevím rady co s tím. Díky za rady.
$multiplier = $form->addMultiplier('multiplier', function (Nette\Forms\Container $container, Nette\Forms\Form $form) {
$container->addDependentSelectBox('item', 'Item:', array($form['event']), function ($values) {
$data = new DependentSelectBoxData();
if (isset($values['event'])) {
$dataItems = $this->optItemFacade->getOptItemsByEventId($values['event'],$this->locale);
return $data->setItems($dataItems);
}else{
return $data;
}
})->setPrompt('- Select Item-')->setRequired()->setDisabledWhenEmpty(TRUE);
$container->addInteger('count','count');
}, 1, 15);
$multiplier->addCreateButton('Add');
$multiplier->addRemoveButton('Remove');
Editoval jarda256 (14. 12. 2016 16:40)
- jarda256
- Člen | 130
<?php
namespace App\Forms;
use NasExt\Forms\Controls\DependentSelectBoxData;
use Nette;
use Nette\Application\UI\Form;
use Nette\Localization\ITranslator;
use App\Model;
class CreateRegistrationFormFactory
{
use Nette\SmartObject;
/** @var Model\Facades\RegistrationFacade*/
protected $registrationFacade;
/** @var Model\Facades\SiteFacade*/
protected $siteFacade;
/** @var Model\Facades\OptItemFacade*/
protected $optItemFacade;
/** @var ITranslator */
private $translator;
/** @var FormFactory */
private $factory;
private $locale;
public function __construct(ITranslator $translator, FormFactory $factory, Model\Facades\RegistrationFacade $registrationFacade,Model\Facades\SiteFacade $siteFacade,Model\Facades\OptItemFacade $optItemFacade)
{
$this->translator = $translator;
$this->factory = $factory;
$this->registrationFacade = $registrationFacade;
$this->siteFacade = $siteFacade;
$this->optItemFacade = $optItemFacade;
}
public function translate($word){
return $this->translator->translate($word);
}
/**
* @return Form
*/
public function create($firstInput,$members,$locale,callable $onSuccess)
{
$form = $this->factory->create();
$this->locale = $locale;
$form->addSelect('event','Event',$firstInput)->setRequired(TRUE)->setPrompt("Select event");
$form->addDependentSelectBox('site', 'Site:', array($form['event']), function ($values) {
$data = new DependentSelectBoxData();
if (isset($values['event'])) {
$dataSite = $this->siteFacade->getNamesByEventId($values['event'],$this->locale);
return $data->setItems($dataSite);
}else{
return $data;
}
})->setPrompt('- Select Site-')->setRequired()->setDisabledWhenEmpty(TRUE);
$form->addMultiSelect('members','Members',$members)->setRequired(TRUE);
$multiplier = $form->addMultiplier('multiplier', function (Nette\Forms\Container $container, Nette\Forms\Form $form) {
$container->addDependentSelectBox('item', 'Item:', array($form['event']), function ($values) {
$data = new DependentSelectBoxData();
if (isset($values['event'])) {
$dataItems = $this->optItemFacade->getOptItemsByEventId($values['event'],$this->locale);
return $data->setItems($dataItems);
}else{
return $data;
}
})->setPrompt('-Select Item-');
$container->addInteger('count','count');
}, 0, 15);
$multiplier->addCreateButton('Add');
$multiplier->addRemoveButton('Remove');
$form->addProtection('Security token has expired, please submit the form again');
$form->addSubmit('send', 'Vytvořit registraci');
$form->onSuccess[] = function (Form $form, $values) use ($onSuccess) {
$this->registrationFacade->createRegistration($values);
$onSuccess();
};
return $form;
}
}
protected function createComponentCreateRegistrationForm($name)
{
$firstInput = $this->eventFacade->getNames($this->locale);
$user = $this->userFacade->getUser($this->user->id);
$team = $user->team;
$members = $this->personFacade->getValidPeople($team->getId());
$form = $this->createRegistrationFactory->create($firstInput,$members,$this->locale,function () {
$this->flashMessage("Registrace byla úspěšně vytvořena", 'success');
$this->redirect(':Web:Registration:show');
});
$this[$name] = $form;
return $form;
}
- jarda256
- Člen | 130
@Martk Chyba vznikne hned jak chci přidat multiplier v základu je tam 0 takže to jde, ale když chci, aby se mi select a integer vykreslil, tak to vyhodí chybu.
EDIT: tak opravda…když nechám v základu vykreslit 2 nebo 1 tak to taky funguje, ale padne to pokaždé když kliknu na tlačítko add
Editoval jarda256 (19. 12. 2016 0:35)