@@ -12,6 +12,7 @@ final class MultistepForm extends \Nette\Application\UI\Control
1212 private string $ subsessionId ;
1313 private int $ currentStep ;
1414 private array $ factories = [];
15+ private array $ templates = [];
1516 private array $ defaults = [];
1617 private bool $ editing = false ;
1718 private bool $ stepSave = false ;
@@ -28,6 +29,13 @@ public function __construct(
2829
2930 public function render () : void
3031 {
32+ if (\count ($ this ->factories ) < $ this ->currentStep ||
33+ \count ($ this ->templates ) < $ this ->currentStep
34+ ) {
35+ throw new \Nette \InvalidStateException ('No factory given ' );
36+ }
37+
38+ $ this ->template ->customTemplate = $ this ->templates [$ this ->currentStep - 1 ];
3139 $ this ->template ->setFile (__DIR__ . '/MultistepForm.latte ' );
3240 $ this ->template ->render ();
3341 }
@@ -39,9 +47,10 @@ public function setFactories(array $factories) : self
3947 return $ this ;
4048 }
4149
42- public function addFactory ($ factory ) : self
50+ public function addFactory ($ factory, string $ templatePath = null ) : self
4351 {
4452 $ this ->factories [] = $ factory ;
53+ $ this ->templates [] = $ templatePath ;
4554
4655 return $ this ;
4756 }
@@ -116,7 +125,7 @@ public function getMaxStep() : int
116125
117126 /**
118127 * Returns all filled values.
119- *
128+ *
120129 * @return array
121130 */
122131 public function getValues () : array
@@ -148,10 +157,6 @@ public function loadState(array $params): void
148157
149158 protected function createComponentForm () : \Nette \Forms \Form
150159 {
151- if (\count ($ this ->factories ) < $ this ->currentStep ) {
152- throw new \Nette \InvalidStateException ('No factory given ' );
153- }
154-
155160 $ factory = $ this ->factories [$ this ->currentStep - 1 ];
156161
157162 if (\is_object ($ factory ) && \method_exists ($ factory , 'create ' )) {
@@ -187,9 +192,9 @@ private function appendButtons(\Nette\Forms\Form $form) : \Nette\Forms\Form
187192 $ previous ->setDisabled ();
188193 }
189194
190- /* if ($this->isEdit()) {
195+ if ($ this -> stepSave && $ this ->isEdit ()) {
191196 $ form ->addSubmit ('quicksave ' , 'Uložit ' );
192- }*/
197+ }
193198
194199 $ next ->onClick [] = function (\Nette \Forms \Controls \SubmitButton $ button ) : void {
195200 $ form = $ button ->getForm ();
0 commit comments