yiisoft/yii2-bootstrap5

ActiveField | Additional fields: checkbox

numitec opened this issue · 9 comments

What steps will reproduce the problem?

I tried to change the vanilla Yii2 checkbox from:

$form->field($model, 'active')->checkBox()

to:

$form->field($model, 'active')->checkBox( ['switch' => True] )

in order to show a fancy switch.

What is the expected result?

Reading the English Guide: https://github.com/yiisoft/yii2-bootstrap5/blob/master/docs/guide/usage-widgets.md, I was expecting to find a beauty switch like: https://getbootstrap.com/docs/5.1/forms/checks-radios/#switches

What do you get instead?

The same checkbox that comes out of the box with Yii2.

Additional info

Q A
Yii vesion 2.0.46 August 18, 2022 (Advanced template which comes with BS5)
PHP version PHP 8.1.11
Operating system Ubuntu 20.04.5 LTS

How does the rendered content look like (html)?

The code view:

<div class="col-md-6">
	<?= $form->field($model, 'active')->checkBox( ['switch' => True] ) ?>
</div>

is rendered like this:

<div class="form-group field-user-active">
<input type="hidden" name="User[active]" value="0"><label><input type="checkbox" id="user-active" name="User[active]" value="1" switch> Active</label>
<div class="help-block"></div>
</div>

Do you override the default template of the active-fields, e.g in active-form?

No: nothing at all.

I've only issued: /usr/local/bin/composer create-project --prefer-dist yiisoft/yii2-app-advanced testapp, and it came to pass that BS5 was installed.

BTW: I've tested:

yii\bootstrap5\Progress::widget( ['percent' => 50, 'label' => '50%', 'class' => 'pogress-bar'] );

and it runs flawlessly.

@numitec can you display more sources? maybe you change template or something like this?

@WinterSilence I resolved using SwitchInput from kartik library:

use kartik\switchinput\SwitchInput;
...

<?= $form->field($model, 'active')->widget( SwitchInput::classname(), [] ); ?>

@numitec sorry but its look like fake - your example in unit test

@WinterSilence, I didn't quite follow you. Could you elaborate it?