| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
🔧 Component for Nette framwork which helps with creation of multistep forms.
This component provides a simple way to create a multistep form. Handles swapping between steps, passing values from previous steps to current one and passing all combined values to final success callback. Also handles common edge cases, such as distinction between multiple instances of one form accessed by one client.
Install package using composer
composer require infinityloop-dev/multistep-form
protected function createComponentMultistepForm() : \Infinityloop\MultistepForm\MultistepForm
{
$multistepForm = $this->multistepFormFactory->create()
->setDefaults(['action' => \App\Enum\EAction::ACTION2])
->setSuccessCallback(function(array $values) {
$this->model->save($values);
});
// first step
$multistepForm->addFactory(function() : \Nette\Forms\Form {
$form = new \Nette\Application\UI\Form();
$form->addProtection();
$form->setTranslator($this->translator);
$form->addSelect('action', 'Akce', \App\Enum\EAction::ENUM)
->setRequired();
return $form;
}, __DIR__ . '/step1.latte');
// second step
$multistepForm->addFactory(function(array $previousValues) : \Nette\Forms\Form {
$form = new \Nette\Application\UI\Form();
$form->addProtection();
$form->setTranslator($this->translator);
if (\in_array($previousValues['action'], [\App\Enum\EAction::ACTION1, \App\Enum\EAction::ACTION2], true)) {
$form->addText('action_1or2', 'Action 1 or 2')
->setRequired();
} else {
$form->addText('action_xyz', 'Action Xyz')
->setRequired();
}
});
return $multistepForm;
}
| Back | FazBrowse Home | New Git URL |