Skip to content

No event on empty filter #879

@ghost

Description

This condition MUST be removed.
Use case : to manage in proper way the "minimum" of checked elements, by default I hide "Check all" and show only if that necessary for finded term. If I remove the term, no only one event is runned and I have no way to capture that filter is empty to adapt UI :(

Example of what I have

let findElementUncheckAll = context => {
    return $('.ui-multiselect-header li:nth-child(2)', $(context).multiselect("widget"));
};

let getMinimum = context => {
    return ($(context).data('namespace-type-multiselect-minimum') || 0)*1;
};

$('select[multiple="multiple"][data-namespace-type-multiselect]').multiselect({
    click: function(e){
        let minimum = getMinimum(this);

        if( $(this).multiselect("widget").find("input:checked").length < minimum ){
            return false;
        }
    },
    create: function(e){
        $('.ui-multiselect-header li:nth-child(3)', $(this).multiselect("widget")).hide();
    },
    beforeopen: function(e){
        let $uncheckAll = findElementUncheckAll(this);

        $uncheckAll.hide();
    }
}).multiselectfilter({
    filter: function(e, matches){
        let $that = $(this);
        let $widget = $that.multiselect("widget");
        let listChecked = $that.multiselect("getChecked");
        let $uncheckAll = findElementUncheckAll(this);
        let matchCount = 0;
        let minimum = getMinimum(this);

        for(const [key, value] of Object.entries(matches)) {
            if( key.match(/^[0-9]+$/) && value.length > 0 && $(value).is(':checked') ){
                ++matchCount;
            }
        }

        $uncheckAll.hide();
        if( 
            matchCount
            && listChecked.length - matchCount > minimum
        ){
            $uncheckAll.show();
        }
    }
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions