ColorlibHQ / AdminLTE

AdminLTE - Free admin dashboard template based on Bootstrap 5
https://adminlte.io
MIT License
44.06k stars 18.16k forks source link

How to use bootstrap-switch in AdminLTE #2255

Closed longfeide2008 closed 5 years ago

longfeide2008 commented 5 years ago

Issue type:

Environment:

Description:

I want to add a switch button to the form.

example: image

I follow the official documentation to include the dependency library.

Instantiation: image

But I found the result to be wrong,All are OFF. image

Comment out drawCallback,The result is correct,But there is no style. image

I need to use bootstrap-switch in AdminLTE DataTables.

REJack commented 5 years ago

Related to bootstrap-switch you should use a method from bootstrap-switch like $('input[name="my-checkbox"]').bootstrapSwitch('state', true);.

Docs: https://bttstrp.github.io/bootstrap-switch/methods.html

longfeide2008 commented 5 years ago

Related to bootstrap-switch you should use a method from bootstrap-switch like $('input[name="my-checkbox"]').bootstrapSwitch('state', true);.

Docs: https://bttstrp.github.io/bootstrap-switch/methods.html

Maybe I didn't describe my problem clearly.

I made a test page

Original state: // $("[name='my-checkbox']").bootstrapSwitch('state', true); image

image

Instantiate: $("[name='my-checkbox']").bootstrapSwitch('state', true); image

image

The test examples are as follows:

https://github.com/longfeide2008/bootstrap-switch-test/archive/master.zip

REJack commented 5 years ago

Try this

            "drawCallback": (function () {
                // 初始化启用禁用按钮
                $('input[name="my-checkbox"]').bootstrapSwitch({
                    'size': 'small',
                    'onColor': 'success',
                    'offColor': 'danger'
                });
                $('input[name="my-checkbox"]:checked').bootstrapSwitch('state', true);
            })

This behavior is a bug from bootstrap-switch.

longfeide2008 commented 5 years ago
$('input[name="my-checkbox"]').bootstrapSwitch({
                    'size': 'small',
                    'onColor': 'success',
                    'offColor': 'danger'
                });
                $('input[name="my-checkbox"]:checked').bootstrapSwitch('state', true);

Thank you very much. Will you build some methods into Adminlte? Include bootstrap-switch because these are very basic.

REJack commented 5 years ago

I looked over bootstrap-switch it's nice, I'll add this to AdminLTE v3 😄

longfeide2008 commented 5 years ago

我查看了bootstrap-switch,这很好,我将其添加到AdminLTE v3 😄

我查看了bootstrap-switch,这很好,我将其添加到AdminLTE v3 😄

Your attitude makes me feel very surprised. I like AdminLte more and more, including your group of lovely developers. I also hope you can work happily and live seriously!

iCheck: image There are also these features that I hope you can build into DataTables.

REJack commented 5 years ago

You can place literally anything in datatables but it depends on what you want to display. If you want to use icheck-bootstrap you need for any checkbox an unique id.

REJack commented 5 years ago

I've added a bootstrap-switch demo in my PR #2256 and created a theme for it.