I have two pageBlocks on the page, one of which I want to validate/submit only when a checkbox is checked. The problem I run into is that validation It has the following javascript:
<script>
function showHideAccount(input, blockId) {
accountBlockDiv = document.getElementById(blockId);
if (!input.checked) {
accountBlockDiv.style.display = 'none';
} else {
accountBlockDiv.style.display = 'block';
}
}
</script>
This is my checkbox:
<apex:inputCheckbox value="{!accountChecked}" id="accountChecked" onclick="showHideAccount(this, '{!$Component.accountBlock}')" />
and this is the pageBlock I want to hide/show:
<apex:pageBlockSection columns="1" id="accountBlock">...
The problem is that it has required fields, and when I hide it, it still attempts to validate. Also it seems like the checkbox boolean value (accountChecked) does not reflect the controller extension's accountChecked value.
I tried doing a rerender on the page when the checkbox is clicked with rendered="{!accountChecked}" and required="{!accountChecked}" on the required fields that cause the issue, but IT DOESN'T DO ANYTHING. Help?