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
Rohan SureshkumarRohan Sureshkumar 

Apex Input Field label attribute not working

This is my code:

<apex:inputField label="Week" value="{! hours_worked__c.pick_a_sunday__c}" id="datepicker" showDatePicker="false"/> 

I don't get any label in the output just an input box. Please suggest a solution
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello,

Is this field in an <apex:pageBlockSectionItem> ? Is so, it's normal, if you include an <apex:outputField> or an <apex:inputField> component in an <apex:pageBlockSectionItem>, these components do not display with their label or custom help text as they do when they are children of an <apex:pageBlockSectionItem>.

Find out more here: http://www.salesforce.com/docs/developer/pages/Content/pages_compref_pageBlockSectionItem.htm (http://www.salesforce.com/docs/developer/pages/Content/pages_compref_pageBlockSectionItem.htm" target="_blank)

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
Rohan SureshkumarRohan Sureshkumar
What is the difference between 'being in an <apex:pageBlockSectionItem> and being a child of 
<apex:pageBlockSectionItem>? They are the same thing right?
 
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello,

No difference at all, if it's in so it is a child.

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
Rohan SureshkumarRohan Sureshkumar
However, if it's the same thing, I don't understand your first answer. How can the label text of the components be visible when they are children of <apex:pageBlockSectionItem>, but not visible when they are included in a <apex:pageBlockSectionItem>, when they both mean the same thing?
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello, 

Indeed! That part is in Salesforce documentation from the link that I provided and surely sounds very confusing. You should ignore this part: 
 "as they do when they are children of an <apex:pageBlockSectionItem>". Hope to have clarified.

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
Rohan SureshkumarRohan Sureshkumar
I figured out the solution.

It seems that the problem was caused due to <apex:inputField> not being a direct child of <apex:pageBlockSection>. The <apex:form > tag was nested in between. I have changed the heirarchy:

<apex:form >
<apex:pageBlock title="Sample">
<apex:pageBlockSection columns="1">
 
<apex:inputField label="Week (select the Sunday):" value="{! hours_worked__c.pick_a_sunday__c}" id="datepicker"   showDatePicker="false"/> 
   
 </apex:pageBlockSection>
</apex:pageBlock>
</apex:form >


And it works - the label is displayed. 
Thanks for your help, Zuinglio
 
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Glad to have helped!