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
brielea1984brielea1984 

Avoid Re-Collapsing PageBlockSection when Validation Rule Error Occurs

On a Visualforce Page, I have a section which is collapsible by default and I use Javascript to toggle it
 
<script type="text/javascript">
    
    $(document).ready(function(){ 
        collapseSections();
        
    });
    
    function collapseSections(){
        $('img[id*="additionalProducts"]').each(function() {
            twistSection(this);
        });
    } 
</script>

<!--Some Code-->

<apex:pageBlockSection title="Service Products" id="additionalProducts" showheader="true" collapsible="true" columns="1">

<!--Some Code-->

The issue I'm having is should the user try to save, and a validation rule is flagged, when the page rerenders the section is collapsed again. I want the section collapsed on the initial page load, but if the user toggles the section down, saves, and hits a validation rule, I'd like the section to remain "uncollapsed".

Any ideas? I have a controller I can add code too as well if needed.

Thanks!
MrTheTylerMrTheTyler
https://help.salesforce.com/apex/HTViewSolution?id=000181821&language=en_US

that might steer you in the right direction
brielea1984brielea1984
Thank you for the response, but I don't think this does what I'm looking for. The link you sent is what I already have implemented. I have the section collapsed by default.

The issue is that when a pagemessage appears because a validation rule is violated, the page rerenders to display the error message - which causes the section to be collapsed again because I have it collapsed by default on page load. 
MrTheTylerMrTheTyler
Well, if it is your javascript which is collapsing all sections, then you should be able to conditionally run it by storing a boolean variable in the controller which is set to true the first time you run your collapseAll().  Use that {!boolean} in your collapseAll() to exit out before collapsing.