arodu / cakelte

AdminLTE plugin for CakePHP
https://packagist.org/packages/arodu/cakelte
MIT License
28 stars 6 forks source link

Unable to implement Select2 #60

Closed bgrinter closed 1 year ago

bgrinter commented 1 year ago

Unable to implement select2 dropdowns and wondering what I've missed or done wrong

AdminLTE allows for select2 dropdowns as seen here https://adminlte.io/themes/v3/pages/forms/advanced.html

CleanShot 2022-12-27 at 17 51 45@2x

I've successfully implemented CakeLTE however am find the dropdowns are just a normal style

CleanShot 2022-12-27 at 17 53 01@2x

Feedback / tips / suggestions greatly appreciated!

bgrinter commented 1 year ago

Ok - worked this one out once I had a deep dive...

The first step was to create a simple app.js file to hold some standard script.

Set a default theme

$.fn.select2.defaults.set('theme', 'bootstrap4');

Then, set all selects to use select2

    $('select option:first-child').each(function() {
            console.log($(this).parent().select2());

            if (!$(this).val()) {
                $(this).parent().select2({
                    debug: true,
                    allowClear: true,
                    placeholder: ''
                });
            } else {
                $(this).parent().select2();
            }
        });

After this, I get my fancy select2 dropdowns.

CleanShot 2022-12-27 at 20 08 10@2x

Hopefully this helps someone else!