Search code examples
salesforceapex-codevisualforce

How to find if an apex:inputField is disabled


From a VisualForce controller, how can I find if a dependent pick-list inputfield is disabled?

There does not seem to be an accessible 'disabled' property for the field. I am creating validation to make sure fields on a visualForce page are filled out. I do not want to do the validation on the dependent pick-list when there are no values to select, and it is in a disabled state.


Solution

  • If a dependent picklist is required and no values are available for it based on the controlling field value, users can save the record without entering a value. The record is saved with no value for that field. Dependent Picklist Considerations

    if its required jest on your page:

    public boolean StateDisabled {get;set;}
      <apex:inputCheckbox styleClass="StateDisabled" style="display:none"  value="{!StateDisabled}" />
    <div>
     <apex:inputField value="{!con.Mailing_Country__c}" onblur="StateDisabled();" />
    </div>              
    <div Class="State"> 
     <apex:inputField value="{!con.Mailing_State_Province__c}" onchange="StateDisabled()"  />
    /div>
    <script>
        function StateDisabled(){
            $(".StateDisabled").attr('checked',true);
            if(!$(".State select").attr('disabled')){
                $(".StateDisabled").attr('checked',false);
            }
        }
    </script>