1

How to disable the button if the list size is 0 or null ? i have selectedcontacts is a collection of list.

<apex:pageblock id="Selected_PBS" title="{!IF(SelectedContacts != NULL && SelectedContacts.size > 0,'Selected Contact','There are no records selected')}">   
        <div align="center" style="padding:15px;" rendered="{!IF(SelectedContacts != NULL && SelectedContacts.size > 0,'Selected Contact','There are no records selected')}">            
              <apex:commandbutton value="Add to Work Order!"/>
        </div>
        <apex:pageBlockTable value="{!SelectedContacts}" var="contact" rendered="{!IF(SelectedContacts != NULL && SelectedContacts.size > 0,true,false)}">
             <apex:column value="{!contact.Name}"/>
             <apex:column value="{!contact.Email}"/>
             <apex:column value="{!contact.Phone}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>  
  • If it were me, I'd probably handle that with Javascript and CSS. I don't know if there is a better way. – Neo Jul 20 '15 at 15:19
4

We have an attribute called disabled in apex:commandButton. You can use it like

<apex:commandButton disabled="{!If(selectedContacts != null && selectedContacts.size > 0,false, true)}">

Here if the selectedContacts size is greater than 0, command button will be enabled as the formula will become disabled=false.

Hope it helps

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.