Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add roaming option (any step is valid) #8

Merged
merged 1 commit into from

2 participants

@idev247

I have a wizard where everything can be a work-in-progress. It doesn't matter if steps are skipped. I only validate data when the person is on the last step of the wizard. The last step for me is a "review" page.

@ProLoser
Owner

How do you validate at the end? Or do you have to do this manually?

@ProLoser ProLoser merged commit 95b12d4 into ProLoser:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 31, 2013
  1. @idev247

    Add roaming option

    idev247 authored
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 6 deletions.
  1. +17 −6 Controller/Component/WizardComponent.php
View
23 Controller/Component/WizardComponent.php
@@ -105,13 +105,20 @@ class WizardComponent extends Component {
public $defaultBranch = true;
/**
* If true, the user will not be allowed to edit previously completed steps. They will be
- * "locked down" to the current step.
+ * "locked down" to the current step. The opposite of $roaming.
*
* @var boolean
* @access public
*/
public $lockdown = false;
/**
+ * If true, the user will be allowed navigate to any steps. The opposite of $lockdown.
+ *
+ * @var boolean
+ * @access public
+ */
+ public $roaming = false;
+/**
* If true, the component will render views found in views/{wizardAction}/{step}.ctp rather
* than views/{step}.ctp.
*
@@ -552,9 +559,11 @@ protected function _validateData() {
return true;
}
/**
- * Validates the $step in two ways:
- * 1. Validates that the step exists in $this->steps array.
- * 2. Validates that the step is either before or exactly the expected step.
+ * Validates the $step four ways:
+ * 1. Explicitly only validate step that exists in $this->steps array.
+ * 2. If $roaming option is true any steps within $this->steps is valid
+ * 3. If $lockdown option is true only the next/current step is valid.
+ * 4. If $roaming and $lockdown is false validate the step either before or exactly the expected step.
*
* @param $step Step to validate.
* @return mixed
@@ -562,7 +571,9 @@ protected function _validateData() {
*/
protected function _validStep($step) {
if (in_array($step, $this->steps)) {
- if ($this->lockdown) {
+ if($this->roaming) {
+ return true;
+ } elseif ($this->lockdown) {
return (array_search($step, $this->steps) == array_search($this->_getExpectedStep(), $this->steps));
}
return (array_search($step, $this->steps) <= array_search($this->_getExpectedStep(), $this->steps));
@@ -572,4 +583,4 @@ protected function _validStep($step) {
}
-?>
+?>
Something went wrong with that request. Please try again.