function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Setting default value on Checkbox


Maybe I'm missing something incredibly obvious but none of the standard visualforce components for checkboxes appear to be correctly setting the default value for my object:


Here's the inputfield version:



              <apex:inputField value="{!webform.Use_Enhanced_Multiselect__c}" />    


Default value of checked/selected does not appear when object is first initialized.


Here's the inputCheckbox version:



              <apex:inputCheckbox  value="{!webform.Use_Enhanced_Picklist__c}" />      

Default value of checked also does not appear when object is first initalized.


Unlike inputfield, I can do this:



              <apex:inputCheckbox selected="true" value="{!webform.Use_Enhanced_Datepicker__c}" />      



But then it always appears checked, even after I update the object.



The only way I've figured out is to use my own enhancedComponent library which allows me to set the defaults:



<c:enhancedCheckbox fieldname="Use_Enhanced_Lookup__c" pageController="{!this}" defaultValue="checked"  />    



This method works fine but I was hoping to use standard components this time around.


Am I missing something obvious?








You can give attribute ‘rendered’ in <apex:inputCheckbox rendered = “{! IF(showcheck == 1,true,false)}”>  AND give the value 1 & 0 in controller wherever you want to check  and uncheck the checkbox.


Hope this helps.