yii2-bootstrap5 icon indicating copy to clipboard operation
yii2-bootstrap5 copied to clipboard

ActiveField | Additional fields: checkbox

Open numitec opened this issue 2 years ago • 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

numitec avatar Dec 01 '22 09:12 numitec

How does the rendered content look like (html)?

simialbi avatar Dec 01 '22 11:12 simialbi

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>

numitec avatar Dec 01 '22 11:12 numitec

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

simialbi avatar Dec 01 '22 11:12 simialbi

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 avatar Dec 01 '22 12:12 numitec

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

WinterSilence avatar Feb 02 '23 19:02 WinterSilence

@WinterSilence I resolved using SwitchInput from kartik library:

use kartik\switchinput\SwitchInput;
...

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

numitec avatar Feb 03 '23 12:02 numitec

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

WinterSilence avatar Feb 04 '23 16:02 WinterSilence

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

numitec avatar Feb 06 '23 10:02 numitec

@numitec https://github.com/yiisoft/yii2-bootstrap5/blob/master/tests/ActiveFieldTest.php#L173

WinterSilence avatar Feb 06 '23 16:02 WinterSilence