+ Start a Discussion
Martha VMartha V 

apex:repeat avoid line breaks

I have a repeat in a visualforce page that displays the fieds in a fieldset. I want the fields to display in two columns (like the standard detail pages), but they would only display all in one cell when using apex:pageBlockSection. 

I tried to add a span to wrap the repeat to add style of width: 50% and display:inline.
It is displaying in two columns, but there seems to be a line break after each field.

Here is the code
<apex:pageBlockSection title="Information" columns="2">
                <apex:inputField value="{!Projects__c.Name}" label="Project Name" required="true"/>
                <apex:outputField value="{!Projects__c.OwnerId}" />
                <span style="display:inline; width:50%;">                
                    <apex:repeat value="{!$ObjectType.Projects__c.FieldSets.projectFieldSet}" var="f"> 
                        <span style="display:inline; width:50%;">
                            <apex:inputField value="{!Projects__c[f.fieldPath]}" label="{!f.Label}" required="{!OR(f.required, f.dbrequired)}"/>
                        </span>
                    </apex:repeat> 
                </span>                                             
            </apex:pageBlockSection>

and here is what I am getting
visualforce page preview

I want to get rid of all the vertical spaces in between the fields. Any ideas?
Best Answer chosen by Martha V
Dushyant SonwarDushyant Sonwar
Hey Martha,

I tried to replicate the issue using account . Try removing the span tag , the span is causing the issue .

It should work fine. 

User-added image
<apex:page standardController="Account">
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockSection title="Information" columns="2">
                <apex:inputField value="{!Account.Name}" label="Account Name" required="true" />
                <apex:outputField value="{!Account.OwnerId}" />
                
                
                    <apex:repeat value="{!$ObjectType.Account.FieldSets.Test}" var="f">
                        
                            <apex:inputField value="{!Account[f.fieldPath]}" label="{!f.Label}" required="{!OR(f.required, f.dbrequired)}" />
                        
                    </apex:repeat>

            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

All Answers

Dushyant SonwarDushyant Sonwar
Hey Martha,

I tried to replicate the issue using account . Try removing the span tag , the span is causing the issue .

It should work fine. 

User-added image
<apex:page standardController="Account">
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockSection title="Information" columns="2">
                <apex:inputField value="{!Account.Name}" label="Account Name" required="true" />
                <apex:outputField value="{!Account.OwnerId}" />
                
                
                    <apex:repeat value="{!$ObjectType.Account.FieldSets.Test}" var="f">
                        
                            <apex:inputField value="{!Account[f.fieldPath]}" label="{!f.Label}" required="{!OR(f.required, f.dbrequired)}" />
                        
                    </apex:repeat>

            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 
This was selected as the best answer
Martha VMartha V
Thanks @Dushyant Sonwar, not sure what I did before that wasn't working. But I took the <span>'s out and now it's working!