You need to sign in to do that
Don't have an account?
Mycodex
uncheck all checkboxes [SOLVED]
I have a series of checkboxes on a visualforce page I created. I have one master checkbox that when it is checked, it deselects all the checkboxes below it. Here is the code for the master checkbox:
It simply runs the actionSupport component with an action of deselectCheckboxes. My extension then fires the following class
As you can see, this is very crude. It does not account for any new checkbox fields automatically. Is there any way I can simply the deselectCheckboxes function to loop through a series of checkboxes with an id of "checkbox1" or something similar?
I could even just ignore the if statement and go straight to setting the checkboxes as false. I was just throwing this out also because I couldn't find any way to change the value of a checkbox easily on these discussion boards.
Message Edited by Mycodex on 08-20-2008 02:52 PM
Code:
<apex:page standardController="Opportunity" extensions="OppControllerExtension" sidebar="true">
...
<apex:pageBlockSectionItem > <apex:outputLabel value="1. Does our agent currently control the business—" for="agent_controls_business"/> <apex:inputcheckbox value="{!opportunity.agent_controls_business__c}" id="agent_controls_business"> <apex:actionSupport event="onclick" rerender="thePageBlock" action="{!deselectCheckboxes}" status="status"> </apex:actionSupport> </apex:inputcheckbox> </apex:pageBlockSectionItem>
It simply runs the actionSupport component with an action of deselectCheckboxes. My extension then fires the following class
Code:
public class OppControllerExtension { private final Opportunity insured; public OppControllerExtension(ApexPages.StandardController stdController){ this.insured= (Opportunity)stdController.getRecord(); } public PageReference deselectCheckboxes() { if (insured.Competition_True__c == true) {insured.Competition_True__c = false;} if (insured.Know_coverage_and_pricing_details__c == true) {insured.Know_coverage_and_pricing_details__c = false;} if (insured.Agent_commited__c == true) {insured.Agent_commited__c = false;} if (insured.agent_allow_us_in_sales_process__c == true) {insured.agent_allow_us_in_sales_process__c = false;} if (insured.account_moved__c == true) {insured.account_moved__c = false;} if (insured.XL_write_other_lines_for_insured__c == true) {insured.XL_write_other_lines_for_insured__c = false;} if (insured.agent_hit_ratio_True__c == true) {insured.agent_hit_ratio_True__c = false;} return null; } }
As you can see, this is very crude. It does not account for any new checkbox fields automatically. Is there any way I can simply the deselectCheckboxes function to loop through a series of checkboxes with an id of "checkbox1" or something similar?
I could even just ignore the if statement and go straight to setting the checkboxes as false. I was just throwing this out also because I couldn't find any way to change the value of a checkbox easily on these discussion boards.
Message Edited by Mycodex on 08-20-2008 02:52 PM
A:
No, it element id's are not visible in the apex code.
you would have to describe the custom sobject, then loop over each field in that description, checking the field type, then setting the value of the checkbox types to false. this uses a describe feature that is not yet available in a production environment.
so, your code is fine and should work.
ps:
change
To make things even easier, ignore the check for true and just set all values to false. This will stop any dereferencing of null issues as well.
So:
[edit:] Oops, just saw you had already realised this. Ignore my post :-) Mark
Message Edited by Mark Young on 08-20-2008 03:15 PM
Please go through the below link for simple example.
http://salesforceglobe4u.blogspot.in/2015/12/select-all-checkbox-in-visualforce-page.html
Let me know in case of any issues.