Skip to content

Commit 87514a1

Browse files
authored
Update README.md
1 parent 800f08c commit 87514a1

File tree

1 file changed

+68
-2
lines changed

1 file changed

+68
-2
lines changed

README.md

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,68 @@
1-
# multistep-form
2-
:wrench: Multistep form component for Nette framwork
1+
# Multistep form
2+
3+
:wrench: Component for Nette framwork which helps with creation of multistep forms.
4+
5+
## Introduction
6+
7+
## Installation
8+
9+
Install package using composer
10+
11+
```
12+
composer require infinityloop-dev/multistep-form
13+
```
14+
15+
## Dependencies
16+
17+
- [nette/application](https://github.com/nette/application)
18+
- [nette/http](https://github.com/nette/http)
19+
- [nette/forms](https://github.com/nette/forms)
20+
21+
22+
## How to use
23+
24+
- Register `\Infinityloop\MultistepForm\IMultiStepFormFactory` as service in cofiguration file.
25+
- Inject it into component/presenter where you wish to use multi step form,
26+
- write createComponent method and use macro {control} in template file
27+
28+
### Example createComponent method
29+
30+
```
31+
protected function createComponentMultistepForm() : \Infinityloop\MultistepForm\MultistepForm
32+
{
33+
$multistepForm = $this->multistepFormFactory->create()
34+
->setDefaults(['action' => \App\Enum\EAction::ACTION2])
35+
->setSuccessCallback(function(array $values) {
36+
$this->model->save($values);
37+
});
38+
39+
// first step
40+
$multistepForm->addFactory(function() : \Nette\Forms\Form {
41+
$form = new \Nette\Application\UI\Form();
42+
$form->addProtection();
43+
$form->setTranslator($this->translator);
44+
45+
$form->addSelect('action', 'Akce', \App\Enum\EAction::ENUM)
46+
->setRequired();
47+
48+
return $form;
49+
}, __DIR__ . '/step1.latte');
50+
51+
// second step
52+
$multistepForm->addFactory(function(array $previousValues) : \Nette\Forms\Form {
53+
$form = new \Nette\Application\UI\Form();
54+
$form->addProtection();
55+
$form->setTranslator($this->translator);
56+
57+
if (\in_array($previousValues['action'], [\App\Enum\EAction::ACTION1, \App\Enum\EAction::ACTION2], true)) {
58+
$form->addAjaxSelect('action_1or2', 'Action 1 or 2')
59+
->setRequired();
60+
} else {
61+
$form->addText('action_xyz', 'Action Xyz')
62+
->setRequired();
63+
}
64+
});
65+
66+
return $multistepForm;
67+
}
68+
```

0 commit comments

Comments
 (0)