1

I am trying to rerender an inputField; but, since it has a rendered attribute, it cannot be rerendered directly. I have tried putting it in a pageblocksectionitem, but that does not work. I have put it in an outputPanel, but it then puts the label above the field, not next to it inline as the other inputFields appear on my page. I want it to appear just like the other inputFields. Can anyone help. Here is the code:

<apex:outputPanel id="endDate">
    <apex:outputLabel value="End Date" 
                             rendered="{!renderEndDate}" /> 
    <apex:inputField id="endDateField"
                         value="{!newMember.End_Date__c}" 
                         required="true" 
                         rendered="{!renderEndDate}" />
</apex:outputPanel>

Thanks in advance.

1
  • can you add some visual to this question .On whats expected and how is it presently Dec 7 '13 at 13:36
2

If you place your label and field inside of a then it will display like a normal label and field with Salesforce styling

<apex:pageBlock >
   <apex:pageBlockSection >
   <apex:pageBlockSectionItem >


    <apex:outputLabel value="End Date" 
                             rendered="{!ShowEndDate}"/> 
    <apex:inputField id="endDateField"
                         value="{!myCon.Birthdate}" 
                         required="true" 
                         rendered="{!ShowEndDate}"/> 

</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
5
  • Thanks for your response. I tried that but it does not work: I see: label on one line and field on next line. All other input fields have label and field on same line. Also, it does not line up with other fields in the column.
    – JimH
    Dec 7 '13 at 14:02
  • Upon further research it seems Salesforce will do this for you if you place your label and field inside of a pageBlockSection Item. I tested and confirmed. I edited my answer Dec 7 '13 at 14:38
  • In my problem, the field is not rendered initially (conditions to render it are not met) so it is not initially displayed -- this is what I expect. However, when the conditions are met to render it, and it is rerendered as in your example, it does not rerender. I think this is because the inputfield has a render attribute (which I need). So what I read says I need to surround the input field in something (like outputPanel, which did not format correctly). If you try to rerender the pageBlockSectionItem (the thing that now surrounds the inputfield), that does not work either.
    – JimH
    Dec 7 '13 at 14:55
  • have you tried wrapping the pageblocksectionitem with a noutput panel and rerendering that> Dec 7 '13 at 15:04
  • Yes, but it had the format issue.
    – JimH
    Dec 7 '13 at 15:05
0

Can you please include the below code and see if it works. If seems working then replace the variables

<apex:page controller="testRender"  >
 <apex:form>
<apex:pageBlock >
    <apex:pageBlockSection   id="reRender" >
       <apex:pageBlockSectionItem >
            <apex:outputLabel value="End Date"    rendered="{! bool }" /> 
             <apex:inputField id="endDateField"    value="{!acc.name}"       rendered="{!bool }" />
          </apex:pageBlockSectionItem>
       </apex:pageBlockSection>
</apex:pageBlock>
<apex:commandButton action="{!rerender}" reRender="reRender" value="Rerender"/>
</apex:form>
</apex:page>

Add this controller

public class testRender{
  public boolean bool {get;set;}
  public Account acc{get;set;}
    public testRender()
    {
      bool  = false;
    }
    public void rerender()
    {
     bool = !bool; 
    }
}
1
  • Thanks for your reply. I need just the single pageblocksectionitem rerendered not the entire pageblocksection (there are other items in the pageblocksection I do not want to rerender).
    – JimH
    Dec 7 '13 at 19:01
0

Not sure if you already found a solution. But I think you can force Salesforce to display a blank section if you don't display the end date, silly example :

<apex:outputPanel id="endDate">
    <apex:outputLabel value="{!IF(renderEndDate,'End Date','')}" />
    <apex:inputField value="{!newMember.End_Date__c}" required="true" rendered="{!renderEndDate}"/>
    <apex:outputText value="" rendered="{!NOT(renderEndDate)}" />
</apex:outputPanel>

In that way, it should keep your field consistent on the same line. I hope that can help

0

I have the same issue, too. And, the solution to the new line in such case is to add style in the head.

<head>
  <style>
    .requiredInput{
      display: inline-block;
    }
  <style>
</head>

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.