Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveField | Additional fields: checkbox #61

Open
numitec opened this issue Dec 1, 2022 · 9 comments
Open

ActiveField | Additional fields: checkbox #61

numitec opened this issue Dec 1, 2022 · 9 comments

Comments

@numitec
Copy link

numitec commented Dec 1, 2022

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
@simialbi
Copy link
Collaborator

simialbi commented Dec 1, 2022

How does the rendered content look like (html)?

@numitec
Copy link
Author

numitec commented Dec 1, 2022

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>

@simialbi
Copy link
Collaborator

simialbi commented Dec 1, 2022

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

@numitec
Copy link
Author

numitec commented Dec 1, 2022

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.

@WinterSilence
Copy link
Contributor

WinterSilence commented Feb 2, 2023

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

@numitec
Copy link
Author

numitec commented Feb 3, 2023

@WinterSilence I resolved using SwitchInput from kartik library:

use kartik\switchinput\SwitchInput;
...

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

@WinterSilence
Copy link
Contributor

WinterSilence commented Feb 4, 2023

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

@numitec
Copy link
Author

numitec commented Feb 6, 2023

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

@WinterSilence
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants