From 18aa6ae12c28a7f122afbcfb319a767a756c5deb Mon Sep 17 00:00:00 2001 From: Andre Schuurman Date: Tue, 20 Oct 2015 10:57:09 +0200 Subject: [PATCH] Fix to make previous steps available if starting point is is higher then step 1 and added support to use 'completed' as start_step. --- README.md | 8 ++++---- WizardWidget.php | 41 +++++++++++++++++++++++------------------ 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 83d0f04..9f406e8 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Once the extension is installed, simply use it in your code by : $wizard_config = [ 'id' => 'stepwizard', 'steps' => [ - [ + 1 => [ 'title' => 'Step 1', 'icon' => 'glyphicon glyphicon-cloud-download', 'content' => '

Step 1

This is step 1', @@ -45,20 +45,20 @@ $wizard_config = [ ], ], ], - [ + 2 => [ 'title' => 'Step 2', 'icon' => 'glyphicon glyphicon-cloud-upload', 'content' => '

Step 2

This is step 2', 'skippable' => true, ], - [ + 3 => [ 'title' => 'Step 3', 'icon' => 'glyphicon glyphicon-transfer', 'content' => '

Step 3

This is step 3', ], ], 'complete_content' => "You are done!", // Optional final screen - 'start_step' => 2, + 'start_step' => 2, // Optional, start with a specific step ]; ?> diff --git a/WizardWidget.php b/WizardWidget.php index 7fb96af..eeb914b 100644 --- a/WizardWidget.php +++ b/WizardWidget.php @@ -40,9 +40,9 @@ class WizardWidget extends Widget { public $steps = []; /** - * @var integer step number to start with (range 1 to number of defined steps) + * @var integer step id to start with */ - public $start_step = 1; + public $start_step = null; /** * @var string optional final complete step content @@ -65,15 +65,15 @@ public function run() { $last_id = key($this->steps); $first = true; + $class = ''; foreach ($this->steps as $id => $step) { - // Previous steps are available, current step is active & next steps are inactive - $class = 'disabled'; - if ($id < $this->start_step-1) { - $class = ''; - } elseif ($id == $this->start_step-1) { + // Current or fist step is active, next steps are inactive (previous steps are available) + if ($id == $this->start_step or is_null($this->start_step)) { $class = 'active'; + } elseif ($class == 'active') { + $class = 'disabled'; } $wizard_line .= ''; + ''; // Setup tab content (first tab is always active) $tab_content .= '
'; @@ -110,17 +110,22 @@ public function run() { $first = false; } + // Add a completed step if defined if ($this->complete_content) { - $wizard_line .= ''; - $tab_content .= '
'.$this->complete_content.'
'; + // Check if completed tab is set as start_step + if ($this->start_step == 'completed') { + $class = 'active'; + } + $wizard_line .= ''; + $tab_content .= '
'.$this->complete_content.'
'; } // Start widget @@ -151,7 +156,7 @@ public function run() { * @return string */ protected function navButton($button_type, $step, $button_id) { - // Always setup an id + // Setup a unique button id $options = ['id' => $button_id.$button_type]; // Apply default button configuration if defined