Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No event on empty filter #879

Open
ghost opened this issue Jul 19, 2022 · 0 comments
Open

No event on empty filter #879

ghost opened this issue Jul 19, 2022 · 0 comments

Comments

@ghost
Copy link

ghost commented Jul 19, 2022

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();
        }
    }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants