leostiw
leostiw

Reputation: 1155

SelectCheckboxMenu - Disable "all-selection"

I have a SelectCheckBoxMenu (Primefaces component) with plenty of entries. However, the user is allowed to select max. 3 items. SelectCheckBoxMenu fullfils almost all my requirements, the only problem is that it offers the possibility to select all items, which i obviously don't need in this case.

Is there any possility to disable the "select-all" option? I am using an event to check the entries for max. 3. I think I could do the same for "select-all" and not allow him to select them, but I don't want to have the "select-all" option at all.

Below the code:

<p:selectCheckboxMenu value="#{services.titelId}" id="titel" 
            panelStyle="width:160px;" rendered="#{!services.isFirma()}"
            label="#{services.prepareTitel()}" style="width:160px;"
            styleClass="checkbox">
            <f:selectItems value="#{meta.getAkadTitelList()}" />
            <p:ajax event="change" listener="#{services.validateTitel()}"
                update="titel" process="@this" />
            <p:ajax event="toggleSelect" update="titel" process="@this" />
</p:selectCheckboxMenu>

In addition, the link to the primefaces-showcase example: https://www.primefaces.org/showcase/ui/input/checkboxMenu.xhtml

Upvotes: 7

Views: 16542

Answers (3)

Ashwini
Ashwini

Reputation: 11

You can add <p:selectCheckboxMenu showHeader="false"......

Upvotes: 0

stg
stg

Reputation: 2797

The previous answer did not work for me under PrimeFaces 5.0, so I took a deeper look in the generated HTML and found a solution for PF5 as well.

For PrimeFaces 5.0 you can remove the "select all" checkbox like this:

.without-selectall .ui-selectcheckboxmenu-header .ui-chkbox {
    display: none; 
}

Now use panelStyleClass-attribute instead of styleClass:

<p:selectCheckboxMenu ...
    panelStyleClass="without-selectall"
>

Upvotes: 19

Daniel
Daniel

Reputation: 37051

You can add css rule to your css file

#titel .ui-chkbox .ui-widget {
     display:none;
}

You should add prependId="false" to your h:form , or in case you don't want to add prependId="false" you can change the #titel .ui-chkbox .ui-widget selector into something like #myForm\3A titel .ui-chkbox .ui-widget (to handle the : id seperator)


In case you want the entire filter row removed you can set

<p:selectCheckboxMenu filter="false"....

Upvotes: 6

Related Questions