form_bootstrap_select.js 2.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
/* ------------------------------------------------------------------------------
*
*  # Bootstrap selects
*
*  Specific JS code additions for form_bootstrap_select.html page
*
*  Version: 1.0
*  Latest update: Aug 1, 2015
*
* ---------------------------------------------------------------------------- */

$(function() {

    // Override defaults
    $.fn.selectpicker.defaults = {
        iconBase: '',
        tickIcon: 'icon-checkmark3'
    }



    // Basic setup
    // ------------------------------

    // Basic select
    $('.bootstrap-select').selectpicker();


    // Dynamic refresh
    $('.rm-alaska').click(function() {
        $('.refresh-example').find('[value=AK]').remove();
        $('.refresh-example').selectpicker('refresh');
    });
    $('.rm-hawaii').click(function() {
        $('.refresh-example').find('[value=HI]').remove();
        $('.refresh-example').selectpicker('refresh');
    });


    // Toggle state
    $('.sel-disable').click(function() {
        $('.disable-example').prop('disabled',true);
        $('.disable-example').selectpicker('refresh');
    });
    $('.sel-enable').click(function() {
        $('.disable-example').prop('disabled',false);
        $('.disable-example').selectpicker('refresh');
    });


    //
    // Additional styling
    //

    // Custom color result color
    $('.bootstrap-select-solid').selectpicker();
    $('.bootstrap-select-solid').on('show.bs.dropdown', function () {
        $(this).find('.dropdown-menu').addClass('bg-slate');
    });


    // Custom menu color
    $('.bootstrap-select-menu-color').selectpicker();
    $('.bootstrap-select-menu-color').on('show.bs.dropdown', function () {
        $(this).find('.dropdown-menu').addClass('bg-teal-400');
    });



    // Methods
    // ------------------------------

    // Single value method
    $('#set-single-value').on('click', function() {
        $('.set-single-value').selectpicker('val', 'NV');
    });


    // Multiple values method
    $('#set-multiple-values').on('click', function() {
        $('.set-multiple-values').selectpicker('val', ['NV','AZ']);
    });


    // Select all method
    $('#select-all-values').on('click', function() {
        $('.select-all-values').selectpicker('selectAll');
    });


    // Deselect all method
    $('#deselect-all-values').on('click', function() {
        $('.select-all-values').selectpicker('deselectAll');
    });


    // Show method
    $('#show-menu').on('click', function() {
        $('.toggle-menu').selectpicker('show');
    });


    // Hide method
    $('#hide-menu').on('click', function() {
        $('.toggle-menu').selectpicker('hide');
    });

});