2

I can get the visualforce page to hide the input field but I'm unsure how to hide the associated label. How can I hide the label as well?

                <apex:inputField value="{!Fiscal_Year__c.name}" onclick="test();"/>
                <apex:pageBlockSectionItem id="isCurrentQ">
                    <apex:outputLabel value="is Current" for="isCurrent"/>
                    <apex:inputField value="{!Fiscal_Year__c.Is_Current__c}" id="isCurrent"/>
                </apex:pageBlockSectionItem>

                </apex:pageBlockSection>
        </apex:pageblock>
    </apex:form>

<apex:includeScript value="{! $Resource.jQuery }"/>
<script type="text/javascript">
    function test(){
        $('[id$="isCurrentQ"]').hide();
     }
</script>
2

Once sure fire way to remove the labels is to put your apex:inputField inside a tag

Like so:

<apex:pageBlockSection id="yearInfoPageBlock" title="Fiscal Year Information">

    <apex:pageBlockSectionItem>
        <apex:inputField value="{!Fiscal_Year__c.name}" onclick="test();"/>
    </apex:pageBlockSectionItem>
    <apex:pageBlockSectionItem>        
        <apex:inputField value="{!Fiscal_Year__c.Is_Current__c}" id="isCurrent"/>
    </apex:pageBlockSectionItem>

</apex:pageBlockSection>

Give it a try!

Oh right.. re-reading your question, that might not be what you are trying to achieve.

If you are trying to "hide" the whole input thing with a bit of Javascript. I would recomment wrapping them in output panels, and then calling "hide" on those.

<apex:pageBlockSection id="yearInfoPageBlock" title="Fiscal Year Information">

    <apex:inputField value="{!Fiscal_Year__c.name}" onclick="test();"/>

    <apex:outputPanel Id="isCurrent"> 
        <apex:inputField value="{!Fiscal_Year__c.Is_Current__c}" id="isCurrent"/>
    </apex:outputPanel>

</apex:pageBlockSection>

<apex:includeScript value="{! $Resource.jQuery }"/>
    <script type="text/javascript">
        function test(){
            $('[id$="isCurrent"]').hide();

            $('[id$="isCurrent"]').hide();
        }
    </script>

Also: are you familiar with the "rendered" tag on all elements, which you can use to control their display (both label and input in the case of form elements) from your Apex controller/other formulaic values?

5
  • I was more trying to get rid of the field and the label. You are correct though. I needed to make the input field a PageBlockSectionItem and add an OutputLabel associated with the input field. Then I hide the PageBlockSectionItem.
    – tjcinnamon
    Jan 21 '16 at 16:51
  • Output panel messes with the alignment. I was able to encapsulate it with a PageBlockSectionItem. However the javascript is not hiding the pageblocksection item. <apex:pageBlockSectionItem id="isCurrentQ"> $('[id$="isCurrentQ"]').hide(); It was working for a bit. I'm not sure what happened. I edited the code to include the pageblocksectionitem. See above.
    – tjcinnamon
    Jan 21 '16 at 17:01
  • The odd thing is that I can hide the PageBlockSection but not the PageBlockSectionItem
    – tjcinnamon
    Jan 21 '16 at 17:10
  • Is there a way to make the output panel conform to the formatting of the rest of the fields in the pageblock? Then I wouldn't have to use pageblocksectionitem which appears to not be working
    – tjcinnamon
    Jan 21 '16 at 17:31
  • I guess controlling pageblockitems does not work because when rendered to the browser it gets the ID of the control.
    – tjcinnamon
    Jan 21 '16 at 19:11
1

Figured it out: Set a dataStyleClass on the apex:pageBlockSectionItem.

here is the VF

<apex:pageBlock>
    <apex:pageBlockSection>
        <apex:pageBlockSectionItem dataStyleClass="page-block-section-item">
            <apex:outputLabel value="My nice field" for="myField"/>
            <apex:inputCheckbox value="{!dummy}" id="myField" styleClass="myField"/>
        </apex:pageBlockSectionItem>
    </apex:pageBlockSection>
</apex:pageBlock>

You can hide the page block section item just by selecting the tag by class then using the parent method.

$('td.page-block-section-item').parent().hide();
1
  • nevermind, it takes out the whole row. But if you don't care that it takes out the row then it will work.
    – tjcinnamon
    Jan 26 '16 at 21:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.