@@ -14,8 +14,7 @@ final class MultistepForm extends \Nette\Application\UI\Control
1414 private array $ factories = [];
1515 private array $ templates = [];
1616 private array $ defaults = [];
17- private bool $ editing = false ;
18- private bool $ stepSave = false ;
17+ private bool $ buttonSubmitted = false ;
1918 private $ successCallback = null ;
2019
2120 public function __construct (
@@ -62,20 +61,6 @@ public function setDefaults(array $defaultValues) : self
6261 return $ this ;
6362 }
6463
65- public function setEditing (bool $ editing = true ) : self
66- {
67- $ this ->editing = $ editing ;
68-
69- return $ this ;
70- }
71-
72- public function setStepSave (bool $ stepSave = true ) : self
73- {
74- $ this ->stepSave = $ stepSave ;
75-
76- return $ this ;
77- }
78-
7964 public function setSuccessCallback (callable $ successCallback ) : self
8065 {
8166 $ this ->successCallback = $ successCallback ;
@@ -112,7 +97,7 @@ public function isLast() : bool
11297 */
11398 public function isEdit () : bool
11499 {
115- return $ this -> editing ;
100+ return false ;
116101 }
117102
118103 /**
@@ -194,18 +179,28 @@ private function appendButtons(\Nette\Forms\Form $form) : \Nette\Forms\Form
194179 $ previous ->setDisabled ();
195180 }
196181
197- if ($ this ->stepSave && $ this -> isEdit ()) {
182+ if ($ this ->isEdit ()) {
198183 $ form ->addSubmit ('quicksave ' , 'Uložit ' );
199184 }
200185
186+ $ form ->onSuccess [] = function (\Nette \Forms \Form $ form ) : void {
187+ if ($ this ->buttonSubmitted ) {
188+ return ;
189+ }
190+
191+ $ this ->onNext ($ form , $ form ->getValues ('array ' ));
192+ };
193+
201194 $ next ->onClick [] = function (\Nette \Forms \Controls \SubmitButton $ button ) : void {
195+ $ this ->buttonSubmitted = true ;
202196 $ form = $ button ->getForm ();
203197 \assert ($ form instanceof \Nette \Forms \Form);
204198 $ this ->onNext ($ form , $ form ->getValues ('array ' ));
205199 };
206200
207201 $ previous ->setValidationScope ([]);
208202 $ previous ->onClick [] = function (\Nette \Forms \Controls \SubmitButton $ button ) : void {
203+ $ this ->buttonSubmitted = true ;
209204 $ form = $ button ->getForm ();
210205 \assert ($ form instanceof \Nette \Forms \Form);
211206 $ this ->onPrevious ($ form , $ form ->getValues ('array ' ));
0 commit comments