Sha256: 8822446e65e53501a9bab32a5398a42a49d133dd1b2c3b231e315d266b665de8

Contents?: true

Size: 1.6 KB

Versions: 27

Compression:

Stored size: 1.6 KB

Contents

(function ($) {

    $.fn.select2filter = function (options) {

        var options = $.extend({
            elementToFilter: "",
            hideparam: "to-hide-id"
        }, options);

        if (options.elementToFilter === "") {
            throw "select2filter: You have to specify elementToFilter option";
        }


        return this.each(function (index, element) {
            var allOptions = $(options.elementToFilter).find("option");
            if ($(options.elementToFilter).val() == "") {
                $(options.elementToFilter).prop("disabled", true);
            }
            var select = this

            $(this).change(function (event) {

                if ($(element).val() != "") {
                    $(options.elementToFilter).select2("destroy");
                    $(options.elementToFilter).html(allOptions);
                    $(options.elementToFilter).val(null);

                    $(options.elementToFilter).find("option").each(function (index, element) {
                        var selectedValue = $(select).val();
                        if ($(this).val() != "" && $(this).attr("data-" + options.hideparam) != selectedValue) {
                            $(this).remove();
                        }
                    });

                    $(options.elementToFilter).prop("disabled", false);
                    $(options.elementToFilter).select2({
                        //allowClear: true,
                        minimumResultsForSearch: 7,
                        dropdownAutoWidth: true

                    });


                }
            });
        })

    }

})(jQuery);

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
alchemy-custom-model-3.2 app/assets/javascripts/alchemy-custom-model/select2filter.js
alchemy-custom-model-3.1.5 app/assets/javascripts/alchemy-custom-model/select2filter.js
alchemy-custom-model-3.1.4 app/assets/javascripts/alchemy-custom-model/select2filter.js
alchemy-custom-model-3.1.3 app/assets/javascripts/alchemy-custom-model/select2filter.js
alchemy-custom-model-3.1.2 app/assets/javascripts/alchemy-custom-model/select2filter.js
alchemy-custom-model-3.1.1 app/assets/javascripts/alchemy-custom-model/select2filter.js
alchemy-custom-model-3.1.0 app/assets/javascripts/alchemy-custom-model/select2filter.js
alchemy-custom-model-2.2.2 app/assets/javascripts/alchemy-custom-model/select2filter.js
alchemy-custom-model-3.0.0 app/assets/javascripts/alchemy-custom-model/select2filter.js
alchemy-custom-model-2.2.1 app/assets/javascripts/alchemy-custom-model/select2filter.js
alchemy-custom-model-2.2.0 app/assets/javascripts/alchemy-custom-model/select2filter.js
alchemy-custom-model-2.1.2 app/assets/javascripts/alchemy-custom-model/select2filter.js
alchemy-custom-model-2.1.1 app/assets/javascripts/alchemy-custom-model/select2filter.js
alchemy-custom-model-2.1.0 app/assets/javascripts/alchemy-custom-model/select2filter.js
alchemy-custom-model-2.0.3 app/assets/javascripts/alchemy-custom-model/select2filter.js
alchemy-custom-model-2.0.2 app/assets/javascripts/alchemy-custom-model/select2filter.js
alchemy-custom-model-2.0.1 app/assets/javascripts/alchemy-custom-model/select2filter.js
alchemy-custom-model-2.0.0 app/assets/javascripts/alchemy-custom-model/select2filter.js
alchemy-custom-model-0.1.9 app/assets/javascripts/alchemy-custom-model/select2filter.js
alchemy-custom-model-0.1.7 app/assets/javascripts/alchemy-custom-model/select2filter.js