Skip to content

Commit

Permalink
Merge branch 'feature/bootstrap-force-v1.5+' into release-branch
Browse files Browse the repository at this point in the history
  • Loading branch information
buttflattery committed Jan 14, 2020
2 parents 8c5e506 + 032bb9e commit 55c0485
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### What is this repository for?

A Yii2 plugin used for creating stepped form or form wizard using `yii\widgets\ActiveForm` and `\yii\db\ActiveRecord`, it uses [smart wizard library](https://github.com/mstratman/jQuery-Smart-Wizard) for creating the form interface that uses 3 builtin and 2 extra themes, moreover you can also create your own customized theme too.
A Yii2 plugin used for creating stepped form or form wizard using `yii\widgets\ActiveForm` and `\yii\db\ActiveRecord`, it uses [smart wizard library](https://github.com/mstratman/jQuery-Smart-Wizard) for creating the form interface that uses 3 builtin and 3 extra themes, moreover you can also create your own customized theme too.

**_Note : It uses limited features of the jquery plugin SmartWizard that suite the needs of the ActiveForm validation so not all options in the javascript plugin library are allowed to be changed or customized from within this plugin._**

Expand Down Expand Up @@ -77,6 +77,7 @@ or add into the `composer.json` file under `require` section
#### Widget options

- `wizardContainerId (string)`: Id of the main container for the wizard.
- `forceBsVersion (int)`: Force use of the bootstrap version in case you have some extension having dependencies on `yiisoft\yii2-bootstrap4` even though you are using `yiisoft\yii2-bootstrap` on the site overall, since the extension checks for yii2-bootstrap4 first and if it finds it will load the yii2-bootstrap4 assets and having both of the extensions installed the widget will always go for the bootstrap4. although we dont recommend doing that but still there are scenarios wher people are using in this manner and fce layout problems. default value for this option is `false` which means widget will detect automatically, you can use the provided constants `FormWizard::BS_3` or `FormWizard::BS_4`.
- `formOptions (array)`: Specify the [ActiveForm](https://www.yiiframework.com/doc/api/2.0/yii-widgets-activeform) properties.
- `labelNext (string)` : Next button label, default value `Next`.
- `labelPrev (string)` : Previous button label, default value `Previous`.
Expand Down Expand Up @@ -267,15 +268,17 @@ Only the following options of the plugin SmartWizard are allowed to be customize
### Widget Constants
- Icons
- `FormWizard::ICON_NEXT` defaults to `'<i class="formwizard-arrow-right-alt1-ico"></i>'`.
- `FormWizard::ICON_PREV` defaults to `'<i class="formwizard-arrow-left-alt1-ico"></i>'`.
- `FormWizard::ICON_FINISH` defaults to `'<i class="formwizard-check-alt-ico"></i>'`.
- `FormWizard::ICON_ADD` defaults to `'<i class="formwizard-plus-ico"></i>'`.
- `FormWizard::ICON_RESTORE` defaults to `'<i class="formwizard-restore-ico"></i>'`.
- Step Types
- Boostrap Versions
- `FormWizard::BS_3` defaults to `3`.
- `FormWizard::BS_4` defaults to `4`.
- Step Types
- `FormWizard::STEP_TYPE_DEFAULT` defaults to `'default'`.
- `FormWizard::STEP_TYPE_TABULAR` default to `'tabular'`.
- `FormWizard::STEP_TYPE_PREVIEW` default to `'preview'`.
Expand Down
31 changes: 26 additions & 5 deletions src/FormWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ class FormWizard extends Widget
*/
public $wizardContainerId;

/**
* Force use of the bootstrap version in case you have some
* extension having dependencies on BS4 even though you are
* using BS3 on the site overall
*
* @var mixed
*/
public $forceBsVersion = false;

/**
* The array of steps that are to be created for the FormWizard,
* this option is compulsary.
Expand Down Expand Up @@ -371,6 +380,12 @@ class FormWizard extends Widget
*/
public $classListGroupBadge = 'success';

/**
* BS VERSION
*/
const BS_3 = 3;
const BS_4 = 4;

/**
* ICONS
* */
Expand Down Expand Up @@ -466,9 +481,15 @@ private function _setDefaults()
$this->classFinish .= 'waves-effect';
}

//is bs4 version
$isBs4 = class_exists(BS4Asset::class);
$this->_bsVersion = $isBs4 ? 4 : 3;
//force bootstrap version usage
if ($this->forceBsVersion) {
$this->_bsVersion = $this->forceBsVersion;
} else {
//is bs4 version
$isBs4 = class_exists(BS4Asset::class);
$this->_bsVersion = $isBs4 ? self::BS_3 : self::BS_4;
}

}

/**
Expand Down Expand Up @@ -545,7 +566,7 @@ classRestore:'{$this->classRestore}',
$pluginOptions['toolbarSettings']['toolbarExtraButtons'] = new JsExpression($jsButton);

//if bootstrap3 loaded
$isBs3 = $this->_bsVersion == 3;
$isBs3 = $this->_bsVersion == self::BS_3;

//cerate the form
$this->createForm($isBs3);
Expand Down Expand Up @@ -744,7 +765,7 @@ public function createBody($index, $formInfoText, $step)
$html .= Html::button(
$this->iconAdd . '&nbsp;Add',
[
'class' => $this->classAdd . (($this->_bsVersion == 3) ? ' pull-right add_row' : ' float-right add_row'),
'class' => $this->classAdd . (($this->_bsVersion == self::BS_3) ? ' pull-right add_row' : ' float-right add_row'),
// 'id'=>'add_row'
]
);
Expand Down

0 comments on commit 55c0485

Please sign in to comment.